C# Enumerable LongCount(IEnumerable)

Description

Returns an Int64 that represents the total number of elements in a sequence.

Syntax


public static long LongCount<TSource>(
  this IEnumerable<TSource> source
)

Parameters

  • TSource - The type of the elements of source.
  • source - An IEnumerable that contains the elements to be counted.

Returns

returns The number of elements in the source sequence.

Example

The following code example demonstrates how to use LongCount to count the elements in an array.


//from  w ww . java2s . c  o  m
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  

     string[] fruits = { "apple", "banana", "mango", 
                           "orange", "Java", "grape" };

     long count = fruits.LongCount();

     Console.WriteLine("There are {0} fruits in the collection.", count);
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Linq »




Enumerable