Implicit Typed Variables

Summary

Using the "var" keyword, the compiler implicitly defines the type of the variable based on the type of expression that initializes the variable. Must have an initializer.

Code Example

class Program { static void Main(string[] args) { var myGroups = new [] { new {Name= "Garden", Members = new [] {"pot.jpg", "spring.jpg", "barbeque.jpg", "flowers.jpg"}}, new {Name = "Friends", Members = new [] {"restaurant.jpg", "dinner.jpg"}} }; } }

This would create a new array of a type that has two rows (row 0 and row 1). Each element is an object with two fields, Name and Members.

Members itself is an array with a different length in each case.