Set Operators: Distinct : Distinct « LINQ « C# / C Sharp






Set Operators: Distinct

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {

        int[] fl = { 2, 2, 3, 5, 5 };

        var uniqueFactors = fl.Distinct();

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

 








Related examples in the same category

1.Use Linq Distinct to get the distinct value in an array
2.prints the unique Category names
3.Distinct Operator
4.Get Distinct departments