Select new value : select new « LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;


public class MainClass{

   public static void Main(string[] args){   
         String[] QueryString = { "One", "Two", "Three", "Four", "Five",
              "Six", "Seven", "Eight", "Nine", "Ten" };

         String[] IndexArray = { "A", "B", "C", "D", "E", "F", "G", "H", "I",
              "J", "K", "L", "M", "N", "O", "P", "Q", "R",
              "S", "T", "U", "V", "W", "X", "Y", "Z" };

         var ThisQuery = from StringValue in QueryString 
            join IndexValue in IndexArray
            on StringValue.Substring(0, 1) equals IndexValue
            select new {StringValue, IndexValue};


         foreach (var ThisValue in ThisQuery)
            Console.WriteLine(ThisValue.IndexValue + " - " + 
               ThisValue.StringValue);

   }
}








22.62.select new
22.62.1.select new clause
22.62.2.Query a List or objects and create new objects
22.62.3.Partitions an array of words into groups according to the first letter of each word.
22.62.4.Constructor new object with select statement
22.62.5.Select new value