Count Even Number With LINQ


/*
This program illustrate the basic linq query, that count the only even numbers form the array (collection of integers). Point to be noted that, we must use System.Linq namespace to perform LINQ feature.
*/


using System;
using System.Linq;

class CountEvenNumberWithLinq
{
static void Main()
{
int[] arr = {1,2,3,4,5,6,7,8,9,10};

var result = from a in arr
    where (a%2 == 0)
    select a;

int counteven = result.ToArray().Length;

Console.WriteLine("Even number is " + counteven);
                Console.ReadLine();

}
}


OUTPUT




Count Even Number With LINQ Count Even Number With LINQ Reviewed by Baljeet Singh on 11:33 Rating: 5

No comments:

Powered by Blogger.