Today i get very good and very simple way to compare two arrays.
.Net provide very simple way to compare sequences with Enumerable.SequenceEqual()
Function SequenceEqual() compare target and source sequence and return Boolean value, so we can know that sequence is similar or not.
for ex.
var ar1 = new[] {1, 2, 3, 4, 5, 6, 7 };
var ar2 = new[] {1, 3, 4, 6 };
var result = ar1.SequenceEqual(ar2);
Console.WriteLine(Result.ToString());
Result : False
Now we want to get that element that is different, for that LINQ gives us best function Except() which works as like below.
if(!result)
{
var differ = ar1.Except(ar2);
Array.ForEach(differ.ToArray(), a => Console.WriteLine(a));
}
Out Put:
2
5
7
Hope this will helps you,
Thanks.


