Select items whose value is less than 10 in an int array in CSharp
Description
The following code shows how to select items whose value is less than 10 in an int array.
Example
using System;/* w w w . j a v a 2s. c o m*/
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
int[] numbers = { 10, 20, 30, 40, 1, 2, 3, 8 };
var subset = from i in numbers
where i < 10
select i;
foreach (var i in subset)
Console.Write("Item: {0} ", i);
Console.WriteLine("resultSet is of type: {0}", subset.GetType().Name);
Console.WriteLine("resultSet location: {0}", subset.GetType().Assembly);
}
}
The code above generates the following result.