I want to make a List<List<int>>
structure so that only distinct sequences of numbers can be added. For this I create an EqualityComparer this way:
public class ListEqualityComparer<TElement> : EqualityComparer<List<TElement>>
{
Object hashHelp1 = new Object();
Object hashHelp2 = new Object();
public override bool Equals(List<TElement> x, List<TElement> y)
{
if (x == null && y == null)
return true;
else if (x == null || y == null)
return false;
else if (x.SequenceEqual(y))
return true;
else
return false;
}
public override int GetHashCode(List<TElement> obj)
{
return (hashHelp1, hashHelp2).GetHashCode();
}
}
so I want two lists to be considered equal, if their sequences of elements are equal.
However, if I try to create
ListEqualityComparer<List<int>> LEC = new ListEqualityComparer<List<int>>();
List<List<int>> list = new List<List<int>>(LEC);
I get an error:
Argument 1: cannot convert from 'MyNamespace.MyFolder.ListEqualityComparer<System.Collections.Generic.List<int>>' to 'System.Collections.Generic.IEnumerable<System.Collections.Generic.List<int>>'
.
What does it actually mean?
On my belief the program should just replace TElement
with List<int>
and go, but obviously something different happens here. I am somehow confused, because I have implemented abother EqualityComparer recently, and the lines
MyStructureEqualityComparer<int, ulong> MSEC= new MyStructureEqualityComparer<int, ulong>();
HashSet<MyStructure<int, ulong>> test = new HashSet<MyStructure<int,ulong>>(MSEC);
were fine. What I am doing wrong?