This is the new feature in C# 3.0. This enable us to declare a variable whose type is implicitly inferred from the expression used to initialize the variable.
var age = 10;
Because the initialization value (10) of the variable age is integer type of age will be treated as integer type of variable. There are few limitation of the var type of variables.
#. They can't be initialized as null.
#. They need to be declared and initialized in the same statement.
#. They can't be used as a member of the class.
Asked In: Many Interviews |