How to Compare 2 generic lists:
List<int> list1 = new List<int> { 1, 2, 3, 5, 6 };
List<int> list2= new List<int> { 1, 2, 3 };
Answer: if you are trying to see if 2 sets are equal, then the best approach is to check the except extension method on Enumerable class. And make sure that the result does not have any entries.
var except = Enumerable.Except(list1, list2);
if (except.Count() > 0)
Console.Write("Not equal");
else
Console.Write("equal");;
Console.Write("Not equal");
else
Console.Write("equal");;
Reference:
No comments:
Post a Comment