Count

Input: IEnumerable<TSource>
Optional expression:TSource => bool

Count simply enumerates over a sequence, returning the number of items:


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

class Program
{
    static void Main()
    {
        int fullCount = new int[] { 5, 6, 7 }.Count();  // 3

        Console.WriteLine(fullCount);

    }
}

The output:


3

You can optionally supply a predicate:


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

class Program
{
    static void Main()
    {
        int digitCount = "java2s.com".Count(c => char.IsDigit(c)); // 3
        
        Console.WriteLine(digitCount);
    
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.