Query
public void Linq13()
{
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
var lowNums =
from n in numbers
where n < 5
select digits[n];
Console.WriteLine("Numbers < 5:");
foreach (var num in lowNums)
{
Console.WriteLine(num);
}
}
Lambda Expression
public void DataSetLinq13()
{
var numbers = testDS.Tables["Numbers"].AsEnumerable();
var digits = testDS.Tables["Digits"];
var lowNums = numbers.Where(n => n.Field("number") < 5).Select(n => digits.Rows[n.Field("number")].Field("digit"));
Console.WriteLine("Numbers < 5:");
foreach (var num in lowNums)
{
Console.WriteLine(num);
}
}
Output
Numbers < 5:
four
one
three
two
zero