var is not a type. This is a convenient short manual recording that saves you a lot of typing. The following two declarations are equivalent:
Dictionary<string,List<int>> dic = new Dictionary<string,List<int>>();
and
var dic = new Dictionary<string,List<int>>();
As you can see, this makes typing and reading easier. And if you want to change the data type, you only need to change the right part.
But where I really like the most, in the foreach loops:
foreach ( var item in someList )
Here, the element automatically takes the correct type, depending on the type of someList, and it allows you to change the type of someList without changing the element's declaration.
In short, var is GREAT and should be used.
EDIT : No, you cannot specify var as a parameter to a function. I think the closest thing you can get is generics. And I also completely forgot to mention anonymous types. With them you should use var.
source share