Execute LINQ Query More Than Once Time
using System;
using System.Linq;
class RerunLinq
{
static void Main()
{
//WITHOUT HELP OF LINQ
Console.WriteLine("Without the help of linq");
int[] arr = {1,2,3,4,5,6,7,8,9,10};
int counteven = 0;
foreach(int i in arr)
{
if(i%2 == 0)
counteven++;
}
Console.WriteLine("Total Number of even is " + counteven);
arr[0] = 2;
counteven =0;
foreach(int i in arr)
{
if(i%2 == 0)
counteven++;
}
Console.WriteLine("Total Number of even is " + counteven);
Console.WriteLine("========================================");
// WITH THE HELP OF LINQ
Console.WriteLine("With the help of linq");
int[] arr1 = {1,2,3,4,5,6,7,8,9,10};
var result = from a in arr1
where (a%2 == 0)
select a;
int counteven1 = result.ToArray().Length;
Console.WriteLine("Total Number of even is " + counteven1);
arr1[0] = 2;
counteven1 = result.ToArray().Length;
Console.WriteLine("Total Number of even is " + counteven1);
}
}
OUTPUT
Execute LINQ Query More Than Once Time
Reviewed by Baljeet Singh
on
11:57
Rating:
![Execute LINQ Query More Than Once Time](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghqaV1swUSdv40fMY8qNmLnjXDBFKF-w-I09iiSiHa_N7xOKv7aCClADqItuTzYJtyiWOXZgUbkGoxhJaZsL0nCMsx1EogVd8ud_UTW5qKksQbHjB6sf6a5cPJpmYSe4bCvLyM7ZvPLhES/s72-c/image.png)
No comments: