How to compare two generic lists in C# 3.0?

Ninja picture Ninja · Feb 16, 2010 · Viewed 10.6k times · Source

Possible Duplicate:
Is there a built-in method to compare collections in C#?

What is the best way to compare to generic two generic lists in C# 3.0?

Answer

Chris Fulstow picture Chris Fulstow · Feb 16, 2010

If you want to compare regardless of element order, try the UnorderedEqual<T> method from here:

Otherwise:

var list1 = new List<int> { 1, 2, 3 };
var list2 = new List<int> { 1, 2, 3 };
var areSame = Enumerable.SequenceEqual(list1, list2);