Transforming numbers into their names - CSharp LINQ

CSharp examples for LINQ:Select

Description

Transforming numbers into their names

Demo Code



using System;/*  w w  w  . j av  a 2 s . c  o m*/
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] names = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
        int[] numbersToName = { 5, 7, 1, 4, 9, 3, 0, 2, 6, 8 };
        var namesOfNumbers = from n in numbersToName select names[n];
        foreach (var name in namesOfNumbers)
        {
            Console.WriteLine("\t{0}", name);
        }
    }
}

Result


Related Tutorials