Distinct Operator
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
public static void Main() {
string[] presidents = {"Grant", "Harding", "Harrison", "Hayes", "Hoover", "Jackson"};
Console.WriteLine("presidents count: " + presidents.Count());
IEnumerable<string> presidentsWithDupes = presidents.Concat(presidents);
Console.WriteLine("presidentsWithDupes count: " + presidentsWithDupes.Count());
IEnumerable<string> presidentsDistinct = presidentsWithDupes.Distinct();
Console.WriteLine("presidentsDistinct count: " + presidentsDistinct.Count());
}
}
Related examples in the same category