NOTE: Before you read on or provide an answer, I know about Enumerable.Distinct, I am asking about specific language support for that method, not about the method itself.
I’ve always wondered why there is no distinct keyword in the C# LINQ keyword set so that I could write:
var items = distinct from x in y
select x;
or
var items = from x in y
select distinct x;
Anybody know why this wasn’t included or why it would be a bad idea to include it? It just feels cumbersome to me that I have to wrap the query just to call Distinct(); a distinct keyword would feel more natural.
NOTE: I know that the Distinct method has overrides to provide a comparer if that is required, but a keyword that uses the default comparer would be great. I could even imagine a distinct by keyword combination so that a comparison operator could be provided inline to the query.
Charlie Calvert has a blog post ("Using Distinct and Avoiding Lambdas") discussing the issue. From the top of the post:
And also, from further down in the post:
TL;DR: There’s no
distinctkeyword for simplicity’s sake, sincedistinctdoes not take a lambda expression.