Search content within the blog

Thursday, May 28, 2009

Using Distinct in LINQ

The code is self explanatory.....

List ages = new List { 21, 46, 46, 55, 17, 21, 55, 55 };

IEnumerable distinctAges = ages.Distinct();

Console.WriteLine("Distinct ages:");

foreach (int age in distinctAges)
{
Console.WriteLine(age);
}

/*
This code produces the following output:

Distinct ages:
21
46
55
17
*/

No comments:

Post a Comment