I need to do an intersect between strings but comparing substrings:
public class MiNumeroEqualityComparer : IEqualityComparer<string> {
public bool Equals(string x, string y) => x.Contains(y);
public int GetHashCode(string obj) => obj.GetHashCode();
}
List<string> lst = new List<string> { "abcXdef", "abcXdef", "abcede", "aYcde" };
List<string> num = new List<string> { "X", "Y", "Z" };
var fin = lst.Intersect(num, new MiNumeroEqualityComparer());
I expect in fin: "abcXdef", "abcXdef", "aYcde"
But it's empty, why?
First I've tried substring with case insensitive with: (without success too)
public bool Equals(string x, string y) => x.IndexOf(y, StringComparison.InvariantCultureIgnoreCase) >= 0;
But empty too.