This documentation is archived and is not being maintained.

How to: Eliminate Duplicate Elements from a Sequence (LINQ to SQL)

Use the Distinct operator to eliminate duplicate elements from a sequence.

The following example uses Distinct to select a sequence of the unique cities that have customers.


IQueryable<String> cityQuery =
    (from cust in db.Customers
    select cust.City).Distinct();

foreach (String cityString in cityQuery)
{
    Console.WriteLine(cityString);
}


Show: