Where - Simple 1
This sample prints each element of an input integer array whose value is less than 500. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value.
public void LinqSample()
{
int[] arr= { 500, 400, 100, 300, 900, 800, 600, 700, 200, 000 };
var lowNums = from result in arr
where result < 500
select result ;
Console.WriteLine("arr < 500:");
foreach (var n in lowNums)
{
Console.WriteLine(n);
}
}
Result:
arr < 500:
400
100
300
200
000
How to open a new window with JavaScript
16 years ago
No comments:
Post a Comment