Partitions an array of words into groups according to the first letter of each word. : select new « LINQ « C# / CSharp Tutorial






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

public class MainClass {
    public static void Main() {

        string[] words = { "b", "c", "a", "ba", "ae", "ch" };

        var wordGroups =
            from w in words
            group w by w[0] into g
            select new { FirstLetter = g.Key, Words = g };

        foreach (var g in wordGroups) {
            Console.WriteLine("Words that start with the letter '{0}':", g.FirstLetter);
            foreach (var w in g.Words) {
                Console.WriteLine(w);
            }
        }
    }
}








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