GroupBy and IEqualityComparer comparer

前端 未结 2 858
执念已碎
执念已碎 2020-12-19 02:37

I was going through the GroupBy method in LINQ :

public static IEnumerable> GroupBy(
    this IEnum         


        
2条回答
  •  佛祖请我去吃肉
    2020-12-19 03:16

    You've provided a nonsensical equality comparer, so your results are going to be nonsensical. Your hash code is based on the reference to the comparer itself, which has nothing to do with anything in your Equals method, and in your Equals method you're saying that two objects are equal if the first object is as long or longer than the second string. This just makes no sense, it even violates basic properties of equality in that the order of the parameters should be irrelevant.

提交回复
热议问题