IEnumberable has an extension method Contains<T> which takes two parameters. The first parameter is the value to check for and the second is an implementation of IEqualityComparer. Looking at IEqualityComparer.Equals it takes two parameters named x and y, for the first and second objects to compare.
My question is X or Y the value from the IEnumerable?
Example
List<string> test = new List<String() { 'a', 'b', 'c' }; test.Contains('d', myComparer);
When it calls to the Equals method for the first value will it be Equals(‘a’,’d’) or Equals(‘d’,’a’)?
It shouldn’t matter – equality should be symmetric. From the docs for
IEqualityComparer<T>.Equals:I don’t believe the usage in
Enumerable.Containsis well-defined, i.e. it could change in a future version. If you just make your equality comparer obey the interface documentation, you’ll be fine.