I want to compare two array in c#. If they are matched go to if condition else go to the else condition. How can we do that in c#.
int[] numbers = new int[] { 1, 2, 3, 4, 5 };
int[] numbers2 = new int[] { 1, 2, 3, 4, 5 };
I want to compare the two arrays like
if(numbers == numbers2){
   do something
}else{
   do something
}
You can use the Enumerable.SequenceEqual() extension method. It does exactly what you want:
if (numbers.SequenceEqual(numbers2)) {
    // do something
} else {
    // do something else
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With