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()); } }
1. | Use Linq Distinct to get the distinct value in an array | ||
2. | Set Operators: Distinct | ||
3. | prints the unique Category names | ||
4. | Get Distinct departments |