Will using 'var' affect performance?
There's no extra IL code for the var
keyword: the resulting IL should be identical for non-anonymous types. If the compiler can't create that IL because it can't figure out what type you intended to use, you'll get a compiler error.
The only trick is that var
will infer an exact type where you may have chosen an Interface or parent type if you were to set the type manually.
As Joel says, the compiler works out at compile-time what type var should be, effectively it's just a trick the compiler performs to save keystrokes, so for example
var s = "hi";
gets replaced by
string s = "hi";
by the compiler before any IL is generated. The Generated IL will be exactly the same as if you'd typed string.