0

I have this code:

        HashSet<int> arr = new HashSet<int> { 1, 1, 2 };

        HashSet<List<int>> arrOfarr = new HashSet<List<int>>();
        arrOfarr.Add(new List<int> { 1,2,3 });
        arrOfarr.Add(new List<int> { 1,2,3 });

Due to arr is a Hashset so obviously it returns {1,2} but I am wondering why arrOfarr returns both similar arrays. How does it works? How to change that to not return duplicate arrays?

Programmer
  • 75
  • 5
  • 1
    You should create a comparer, class which implements `IEqualityComparer` – Dmitry Bychenko Jan 15 '22 at 20:11
  • 2
    Also see [Why does C# not implement GetHashCode for Collections?](https://stackoverflow.com/questions/2907372/why-does-c-sharp-not-implement-gethashcode-for-collections) – gunr2171 Jan 15 '22 at 20:14

0 Answers0