Search This Blog

Wednesday, March 19, 2014

Var C# Example

C#Types > Var

Var is implicitly typed.

An implicitly typed local variable is strongly typed, but 

the compiler determines the type. 


Example


// var is required because the select clause specifies an anonymous type 

var query = from prod in products
            where prod.Category == "shoes"
            select new { prod.Name, prod.Price };

// var is required because item is an anonymous type
foreach (var item in query)
{
               

}