Select - Transformation

This sample prints the name of each number in an integer array by indexing into a second array that contains the names.


 








using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication8

{

class Program

{

  static void Main(string[] args)

   {

    int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

     string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven",      "eight", "nine" };


     var textNums =

         from n in numbers

         select strings[n];


       Console.WriteLine("Number strings:");

       foreach (var s in textNums)

      {

        Console.WriteLine(s);

       }


       Console.ReadLine();

     }

   }

}



 Output:-


                    

Aspnet Related Tutorials

...more

New Aspnet Resources

...more

Copyright © 2013 VisualBuilder. All rights reserved