문제

When using the query operator Distinct() the types in the queried sequence must either provide suitable overloads of GetHashCode() and Equals() or you have to pass an implementation of IEqualityComparer<T>.

My question: Why is there no overload of Distinct() accepting a Delegate instance (e.g. Comparison<T>)? - If it was existent a more lighweight lambda expression could be passed (more lightweight than an implementation of IEqualityComparer<T>). - Am I missing something here?

도움이 되었습니까?

해결책

Because it uses GetHashCode().
You cannot make a delegate that gives hash codes.

It could take two delegates, but that would be confusing.

It would be better to ask why there isn't a DistinctBy() method that takes a projection.

다른 팁

otherwise you can try MoreLINQ and its method DistincBy

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top