Skip to main content

C# Check Two Lists<T> Are Equal

Quick method for check if two given lists of objects are equal:

static public bool AreListsEqual<T>(List<T> list1, List<T> list2)
{
    if (object.ReferenceEquals(list1, list2)) return true;
    return list1.Count == list2.Count && !list1.Except(list2).Any() && !list2.Except(list1).Any();
}