Is there way to use Distinct in LINQ query syntax?

VB has this functionality if you place the distinct after select.


There is no Distinct() method syntax in the language integrated query syntax. The closest you could do would be to move the current call:

var q = (from c in tbl
         select c.TABLE_TYPE).Distinct();

(from c in tbl select c.TABLE_TYPE).Distinct();

The Distinct extension method in LINQ does not have a query syntax equivalent.

See https://docs.microsoft.com/en-us/archive/blogs/charlie/linq-farm-using-distinct-and-avoiding-lambdas for additional information as to why.

Tags:

C#

Linq