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();
}

 


Revision #1
Created 11 February 2025 10:11:46 by glwhite
Updated 19 March 2025 15:40:50 by glwhite