Since .NET 3.5 the keyword "var" was introduced into the C# language. I used to think it was an oddity, mostly used by programmers who don't feel like declaring all their variables at the beginning of a methods, or simply liked to use it as a "shortcut" in some situations. Most of the examples I saw over the years where just that.
Recently, however, I've started to use Resharper, to assist me in my development projects. And Resharper continuously suggests to replace my declared variables with var constructs.
Hence my question: to var, or not to var? When do I use var, and when do I not. Is there a rule of thumb, or just a simple personal preference?
To var or not to var
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


VulpesRank #55 · 29.2K reputationPosted Jun 15, 2012, 7:04 AM EDT
http://www.c-sharpcorner.com/uploadfile/b942f9/when-should-you-use-the-var-keyword-in-C-Sharp/
Olivier Muhring151 reputationPosted Jun 15, 2012, 7:21 AM EDT
Ofcourse, other views are also welcome.