Someone asked that question on here already. In short, no, the IL code generated is the same. Therefore, no perf hit. If you ever wonder how one way of doing something differs from another, just write a sample and then use Reflector to analyze the differences.
+6
A:
Kilhoffer
2009-11-18 14:32:24
then the question should be closed as duplicate, shouldn't it?
ax
2009-11-18 14:34:21
Thanks for the link. I searched SO, but couldnt find anything about this.
2009-11-18 14:53:55
+4
A:
Since this is a compile-time feature, there could conceivably be slower compilation times, but not slower run-times.
Gary McGill
2009-11-18 14:32:55
+2
A:
This feature is called type inference. Compiler will infer the correct type at compile time and the msil generated will contain the correct type
Tinku
2009-11-18 14:34:58
+1
A:
Does he mean at compile time or at runtime?
At runtime, it is not possible to have a performance hit. The var
keyword is handled entirely by the compiler, and it is completley impossible to tell from the IL whether the var
keyword was used. Your friend might be thinking of C# 4's new dynamic
keyword, which does have a performance impact.
At compile time, there might be a tiny performance impact, but it's nothing to worry about.
SLaks
2009-11-18 14:37:23