What is the use of var keyword in C#?

 Posted by SheoNarayan on 12/22/2008 | Category: C# Interview questions | Views: 10297

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 are:

#. 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 | Alert Moderator 

Comments or Responses

Login to post response