var keyword
var keyword
It is introduced from C# 3.0.
- With the help of varkeyword we can declare a local variable (or) method variable.
- var type variable can not be passed as parameter to a method.
- var type variable must be initialized during declaration itself.
- var type variable should not be initialized with null but it can contain reference of object
Advantage of var type variable
- No burden of boxing and unboxing.
- Type safty can be achived.
Usage of var type variable
We can find usage of var type variable while working with LINQ.