given the following code:
string[] colors = {"red","green","blue","red","green","blue"};
var distinctColors = (from c in colors select c).Distinct();
distinctColors.Dump();
Is it possible to fold the call .Distinct() into the embedded query syntax?
something like int T-SQL
select distinct color from TableofColors
C#’s query expression syntax doesn’t include “distinct”. VB’s does, however – for example, from the MSDN docs for VB’s Distinct clause:
The C# equivalent would have to explicitly call
Distinct()in dot notation.However, your example can still be simplified:
Don’t think you have to use query expressions to use LINQ 🙂