Where Simple 1

[Back to LINQ examples]

This is one of the LINQ examples designed to show LINQ operating over standard Java collections. In this case the batch version is just ordinary Java iteration.

print("Numbers < 5:");
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
for (int x : numbers) {
    if (x < 5)
        print("{0}", x);
}

Original LINQ code:

public void Linq1()
{
    int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

    var lowNums =
        from n in numbers
        where n < 5
        select n;

    Console.WriteLine("Numbers < 5:");
    foreach (var x in lowNums)
    {
        Console.WriteLine(x);
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License