Distinct Operator : Distinct « LINQ « C# / CSharp Tutorial






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());
    }
}








22.31.Distinct
22.31.1.Create the Distinct query
22.31.2.Use Linq Distinct to get the distinct value in an array
22.31.3.Set Operators: Distinct
22.31.4.Printing the unique Category names
22.31.5.Distinct Operator
22.31.6.Get Distinct departments
22.31.7.Get all Make and don't show duplicates