Quantcast
Channel: jordan.terrell - LINQ: Distinct() does not work as expected
Viewing all articles
Browse latest Browse all 8

David Meyer on LINQ: Distinct() does not work as expected

$
0
0
Hahaha, I ran into that same problem. That is definitely messed up. I expected an overload with a selector too. Or at least an equality comparer in the form of a delegate (like Func<T, T, bool>). But an equality comparer interface?! That should be illegal. Lol. Since lambda expressions in C# 3.0, that should at least be considered a very poor design anyway...

One of the great things about LINQ is how well it communicates intent, and your group by, etc. solution does circumvent that (losing meaning, like you said). I agree there should be another Distinct overload. items.Distinct(x => x.PropertyToCompare) would be much more readable. Let me know if you write such an extension method; I would want to add that to my common library as well! Smile

Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images