Instantiating and Initializing an Anonymous Type Using Object Initialization : var « LINQ « C# / C Sharp






Instantiating and Initializing an Anonymous Type Using Object Initialization

 


using System;
public class MainClass {
    public static void Main() {

        var address = new {
            address = "First Street",
            city = "Vancouver",
            state = "GA",
            postalCode = "99999"
        };

        Console.WriteLine("address = {0} : city = {1} : state = {2} : zip = {3}",
         address.address, address.city, address.state, address.postalCode);
        Console.WriteLine("{0}", address.GetType().ToString());
    }
}

 








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.An Example of Collection Initialization