The use of var
has no bearing on the compiled code or it's efficiency. It is sometimes mandatory - when dealing with anonymous types - but used incorrectly it won't compile. If it does compile, it will result in the same code as it if you had explicitly used the type of the expression on the RHS of the assignment.
Occasionally, you may want to explicitly specify an interface or super-type on the LHS of an assignment and leverage an implicit cast. This has no clean equivalent with the use of var. e.g.
/* Given these classes */
class Animal {}
class Dog : Animal {}
/* This has no simple var equivalent */
Animal animal = new Dog();
/* Since this would make animal of type Dog */
var animal = new Dog();
/* But you can do this - don't why you'd want to though */
var animal = (Animal)new Dog();
For the most part, use of var is merely a matter of style.
In Resharper, you can decide how opportunities to use var are indicated - look in Settings>Code Insepction>Inspection Severity where two entries pertain to var:
- Use 'var' keyword when initializes explicitly declares type (defaults as a Suggestion)
- Use 'var' keyword when possible (defaults as a Hint)
You can change these as you like.