HashSet is pretty close, but ==does not compare values ββin collections. SetEqualswill return true if they contain the same value. However, the order is not taken into account. You can use SequenceEqualif order is important.
static void Main(string[] args)
{
HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
HashSet<int> set2 = new HashSet<int> { 2, 1, 3 };
HashSet<int> set3 = new HashSet<int> { 1, 2, 3 };
Console.WriteLine(set1.SetEquals(set2));
Console.WriteLine(set1.SequenceEqual<int>(set2));
Console.WriteLine(set1.SequenceEqual<int>(set3));
}
source
share