An Example of Collection Initialization : var « LINQ « C# / C Sharp






An Example of Collection Initialization

 


using System.Collections.Generic;
using System;
public class MainClass {
    public static void Main() {
        List<string> presidents = new List<string> { "AAAA", "BBBBBB", "CCCCCCCC" };
        foreach (string president in presidents) {
            Console.WriteLine(president);
        }
    }
}

 








Related examples in the same category

1.Using var
2.Anonymous Types
3.An Anonymous Type Assigned to a Variable Declared with the var Keyword
4.Instantiating and Initializing an Anonymous Type Using Object Initialization