Use Aggregate Operators: Count : Count « LINQ « C# / C Sharp






Use Aggregate Operators: Count

 

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

public class MainClass {
    public static void Main() {
        int[] factorsOf300 = { 2, 2, 3, 5, 5 };

        int uniqueFactors = factorsOf300.Distinct().Count();

        Console.WriteLine("There are {0} unique factors of 300.", uniqueFactors);
    }
}

 








Related examples in the same category

1.Count with string value
2.Count with string operator
3.The aggregation operators return a scalar value
4.Conditional Count
5.Nested Count