Count in Linq

Gopesh9
Posted by Gopesh9 under LINQ category on | Points: 40 | Views : 1039
A simple example showing how you can count the odd number in the array using Linq.

int[] numbers = { 6, 2, 1, 1, 9, 8, 2, 7, 2, 0 }; 
int odd = numbers.Count(no => no % 2 == 1);
Console.WriteLine("The number of odd numbers in the list is ", odd);

Comments or Responses

Login to post response