using select to make a projection of the items - CSharp LINQ

CSharp examples for LINQ:Projection

Description

using select to make a projection of the items

Demo Code



using System;//w  w  w.j av  a2  s .  com
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] inputs = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        var outputs = from i in inputs select i + 2;  // OK to put whole query on one line.
        int k = 0;
        foreach (int n in outputs)
        {
            Console.WriteLine("\t{0} --> {1}", inputs[k], n);
            k++;
        }

    }
}

Result


Related Tutorials