Conditional 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[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

        int oddNumbers = numbers.Count(n => n % 2 == 1);

        Console.WriteLine("There are {0} odd numbers in the list.", oddNumbers);
    }
}








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