Microsoft says that the var keyword can be used to instruct the compiler to “infer the type of the variable from the expression on the right side of the initialization statement”. You can use var for a built-in type, a user-defined type, an anonymous type or type that is defined by the .Net framework library.
You should reconsider using var because of:
- Readability
It makes your code harder to read. You or another developer may have a difficult time figuring out what you were doing. - Mistakes
You could change the inferred value of your variable and have to spend more time debugging your code. - More Typing
You may have to type a few more characters when using string or double over var. How much time does it save?
Just because C# allows you to use var doesn’t mean you should. Even Microsoft suggests using var for anonymous types. To help keep your code consistent and readable, use var when necessary.