You could use
Distinct
method of collection.
Distinct
removes all duplicate elements in a collection. It returns only the distinct elements. The System.Linq namespace provides this extension method.
static void Main()
{
List<int> list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(3);
list.Add(4);
list.Add(4);
list.Add(4);
foreach (int value in list)
{
Console.WriteLine("Before: {0}", value);
}
List<int> distinct = list.Distinct().ToList();
foreach (int value in distinct)
{
Console.WriteLine("After: {0}", value);
}
}
Hope this would help you :)
-KR