Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Can the C# ‘var’ keyword be misused?

0.00/5 (No votes)
10 Jul 2011 3  
I've always used var because ReSharper suggested it by default. However, like most people, I only did this when I didn't understand the conotations of ReSharper's suggestion. Now I disable this suggestion in the plug-in, and in actual fact, I prefer to use the fully qualified name on at least...

I've always used var because ReSharper suggested it by default. However, like most people, I only did this when I didn't understand the conotations of ReSharper's suggestion. Now I disable this suggestion in the plug-in, and in actual fact, I prefer to use the fully qualified name on at least one side of the operand. This still means I use var occasionally.


Having used StyleCop in a few of the places I've worked, I came to the conclusion that it does not matter what style of language you use, whether you use var or not - so long as you and your team all agree to that style for the project.


The only thing that truly makes code unmaintainable is inflexible developers who cannot accept that there's is not the only way in the world. Better to learn to just reach a consensus with the rest of the team.


We agree on the maximum amount of whitespace, whether the using statement should be inside the namespace declaration or outside (as default). We also choose whether to add a signature to our classes (making it easier to ask questions about a potentially unmaintainable class - and many other things.


In the long run though - little issues like this are less important than achieving working deliverables.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here