Local variables can be given an inferred "type" of var instead of an explicit type. The var keyword instructs the compiler to infer the type of the variable from the expression on the right side of the initialization statement. The inferred type may be a built-in type, an anonymous type, a user-defined type, or a type defined in the .NET Framework class library. The following examples show various ways in which local variables can be declared with var : // i is compiled as an int var i = 5; // s is compiled as a string var s = "Hello" ; // a is compiled as int[] var a = new [] { 0, 1, 2 }; // expr is compiled as IEnumerable<Customer> // or perhaps IQueryable<Customer> var expr = from c in customers where c.City == "London" select c; // anon is compiled as an anonymous type var anon = new { Name = "Terry" , Age = 34 }; // list is compiled as List<int> var ...
(Helping you out with C#, ASP.NET, SQL, Microsoft Azure, MVC & Javascript)