Search content within the blog

Thursday, May 28, 2009

Using Count in LINQ

The code is self explanatory....
string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape" };

int numberOfFruits = fruits.Count();
"There are {0} fruits in the collection.",

catch (OverflowException)
Console.WriteLine("The count is too large to store as an Int32.");
Console.WriteLine("Try using the LongCount() method instead.");

// This code produces the following output:
// There are 6 fruits in the collection.

No comments:

Post a Comment