Possible Duplicate:
C# 'var' vs specific type performance
Are there any performance costs (in terms of type conversion, etc.) if I write the line
SqlConnection c = new SqlConnection(connectionString))
as
var c = new SqlConnection(connectionString))
No. The compiled IL is identical.
The only potential side effect is in the case of inheritance, if you’re variable definition is a base class, and you instantiate a subclass. If you do:
This will potentially act differently than:
This is because the second compiles to:
In most cases, it should behave identically (due to the Liskov substitution principle). However, if
DerivedClassuses method hiding it is possible to have a change in behavior.