Implicitly typed variables var

suggest change

The var keyword allows a programmer to implicitly type a variable at compile time. var declarations have the same type as explicitly declared variables.

var squaredNumber = 10 * 10;
var squaredNumberDouble = 10.0 * 10.0;
var builder = new StringBuilder();
var anonymousObject = new
{ 
    One = SquaredNumber,
    Two = SquaredNumberDouble,
    Three = Builder
}

The types of the above variables are int, double, StringBuilder, and an anonymous type respectively.

It is important to note that a var variable is not dynamically typed. SquaredNumber = Builder is not valid since you are trying to set an int to an instance of StringBuilder

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents