linq Distinct

linq Distinct

This sample uses Distinct to remove duplicate elements in a sequence of factors of 300.
public static void Distinct()
        {
            int[] factorsOf300 = { 2, 2, 3, 5, 5 };

            var uniqueFactors = factorsOf300.Distinct();

            Console.WriteLine("Prime factors of 300 :");
            foreach (var f in uniqueFactors)
            {
                Console.WriteLine("Factor {0}", f);
            }
        }


The returned sequence contains the unique elements from the input sequence.
Graphic showing the behavior of Distinct().

Output

Linq Set Operators


linq Distinct linq Distinct Reviewed by Bhaumik Patel on 7:01 PM Rating: 5