Use Aggregate Operators: Count : Count « LINQ « C# / CSharp Tutorial






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








22.29.Count
22.29.1.Count with string value
22.29.2.Count with string operator
22.29.3.The aggregation operators return a scalar value
22.29.4.Use Aggregate Operators: Count
22.29.5.Conditional Count
22.29.6.Nested Count
22.29.7.Numeric Aggregates: count
22.29.8.Count elements in a Range