Click here to Skip to main content
13,558,939 members
Click here to Skip to main content
Articles » Languages » C# » General » Alternatives
Add your own
alternative version

Tagged as


1 bookmarked
Posted 19 Nov 2009
Licenced CPOL

Can the C# ‘var’ Keyword be Misused?

, 19 Nov 2009
Can the C# ‘var’ keyword be misused?


Members may post updates or alternatives to this current article in order to show different approaches or add new features.

10 Jun 2011
If the right-hand operand of an assignment is a "new", there's no need to explicitly specify the type of the new variable being created unless the new variable will have to hold items of a more general type than the right-hand operand would indicate. I would consider the code clearer without the...
10 Jul 2011
Chris Randle
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...
25 Jul 2011
Steve Wellens
6 alternatives  
Misuse of the C# var keyword.
19 Nov 2009
I agree that in the above example, the use of var is a bit excessive. However, for very long types (such as a dictionary with the key and value both being lists of some nested classes... see below code example), this might actually improve readability (seeing so many details may overwhelm you). Assu
12 Jul 2011
The original question was whether this practice can lead to misuse. Of course it can - almost everytime it is used! In the "real world" (business), most programmers spend their days working amongst reasonably old code with several bolt-on fixes. It becomes increasingly hard to maintain because...
10 Jun 2011
I think this is a nice future, for example look this code:Dictionary > myDic = new Dictionary >();We really need to tell the compiler in this expression what the type of myDic is?This is more concise and clear at...


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Aviad P.
Software Developer (Senior)
Israel Israel
Software developer since 1984, currently specializing in C# and .NET.

| | Privacy | Terms of Use | Mobile
Web03 | 2.8.180515.1 | Last Updated 20 Nov 2009
Article Copyright 2009 by Aviad P.
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid