Click here to Skip to main content
12,821,670 members (36,274 online)
Click here to Skip to main content
Articles » Languages » C# » General » Alternatives
Alternatives (6)
Add your own
alternative version

Tagged as


6 bookmarked
Posted 19 Nov 2009

Can the C# ‘var’ keyword be misused?

, 25 Jul 2011 CPOL
Misuse of the C# var keyword.


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

19 Nov 2009
Aviad P.
Can the C# ‘var’ keyword be misused?
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...
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

Steve Wellens
EndWell Software, Inc.
United States United States
I am an independent contractor/consultant working in the Twin Cities area in Minnesota. I work in .Net, Asp.Net, C#, C++, XML, SQL, Windows Forms, HTML, CSS, etc., etc., etc.

| | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 25 Jul 2011
Article Copyright 2009 by Steve Wellens
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid