Neither of those is absolutely true; var
can have both positive and negative effects on readability. In my opinion, var
should be used when either of the following is true:
- The type is anonymous (well, you don't have any choice here, as it must be var in this case)
- The type is obvious based upon the assigned expression (i.e.
var foo = new TypeWithAReallyLongNameTheresNoSenseRepeating()
)
var
has no performance impacts, as it's syntactic sugar; the compiler infers the type and defines it once it's compiled into IL; there's nothing actually dynamic about it.