Click here to Skip to main content
15,895,656 members

Survey Results

How often do you use the var type in C#? (1= never, 5=always)   [Edit]

Survey period: 17 Aug 2009 to 24 Aug 2009

The var keyword can be a saint or a sinner. Choose "1" if you never use var in this scenario (or never use that scenario), up to "5" for always, whenever possible. (Suggested by Asher)

OptionVotes12345 
In normal C# coding (1 = you don"t code in C#, 5=for all C# variables possible)9370%0%0%0%0%
With LINQ9370%0%0%0%0%
For declaring complex types9370%0%0%0%0%
For using complex types (eg in foreach loops)9370%0%0%0%0%
With anonymous types9370%0%0%0%0%
When it saves typing9370%0%0%0%0%
When it makes the code look better (to you)9370%0%0%0%0%

View optional text answers (46 answers)


 
GeneralWhere What and How Pin
drweb8619-Aug-09 20:31
drweb8619-Aug-09 20:31 
GeneralTake a look at the C# language specification Pin
Jörgen Sigvardsson19-Aug-09 7:45
Jörgen Sigvardsson19-Aug-09 7:45 
GeneralRe: Take a look at the C# language specification Pin
Adam Maras19-Aug-09 19:30
Adam Maras19-Aug-09 19:30 
Generalvar is Awesome! Pin
Dale Thompson18-Aug-09 8:42
Dale Thompson18-Aug-09 8:42 
GeneralRe: var is Awesome! Pin
nsimeonov18-Aug-09 10:58
nsimeonov18-Aug-09 10:58 
GeneralRe: var is Awesome! Pin
yassir hannoun18-Aug-09 11:16
yassir hannoun18-Aug-09 11:16 
GeneralRe: var is Awesome! Pin
Hal Angseesing25-Aug-09 6:31
professionalHal Angseesing25-Aug-09 6:31 
GeneralIt hinders backward compatibility [modified] Pin
PIEBALDconsult18-Aug-09 6:55
mvePIEBALDconsult18-Aug-09 6:55 
Don't use var in a program that doesn't otherwise rely on features that were introduced in .net 3.0 (e.g. Anonymous Types).

A .net program should compile on as many versions of the framework as practical. I'm not saying you shouldn't use Generics, Anonymous Types, or Extension Methods; if you use them, that's fine. But var is really just an enabling technology; it enables the use of Anonymous Types. If you're not using Anonymous Types, then you don't need var.

If you write an Awesome Class and publish it here, someone may want to use it, that's the whole point of publishing. If that person is limited to .net 2.0 and your code contains var, but no other .net 3.x and C# 3.0 features, he will have to edit your code to replace all those needless vars. The same goes for Extension Methods; use them sparingly.


The main point here is to consider future users of the code. You yourself may change jobs and be limited in what versions you can use.

Make the most with the least.

modified on Tuesday, August 18, 2009 1:02 PM

Generalvar works in .NET 2.0... Pin
Dale Thompson18-Aug-09 8:44
Dale Thompson18-Aug-09 8:44 
GeneralRe: var works in .NET 2.0... Pin
PIEBALDconsult18-Aug-09 9:05
mvePIEBALDconsult18-Aug-09 9:05 
GeneralFunctional Languages Pin
Kevin McFarlane18-Aug-09 1:16
Kevin McFarlane18-Aug-09 1:16 
General"CCtrlList" <- Pin
fkhg117-Aug-09 20:54
fkhg117-Aug-09 20:54 
GeneralRe: "CCtrlList" <- Pin
Marc Clifton18-Aug-09 15:58
mvaMarc Clifton18-Aug-09 15:58 
GeneralMade Me Uncomfortable, but PinPopular
W Balboos, GHB17-Aug-09 6:03
W Balboos, GHB17-Aug-09 6:03 
GeneralOh, get over it! Pin
David Veeneman17-Aug-09 5:53
David Veeneman17-Aug-09 5:53 
GeneralRe: Oh, get over it! Pin
Netblue17-Aug-09 7:35
Netblue17-Aug-09 7:35 
GeneralRe: Oh, get over it! Pin
David Veeneman17-Aug-09 12:25
David Veeneman17-Aug-09 12:25 
GeneralRe: Oh, get over it! Pin
PIEBALDconsult17-Aug-09 13:04
mvePIEBALDconsult17-Aug-09 13:04 
GeneralRe: Oh, get over it! Pin
AlwiNus17-Aug-09 15:37
AlwiNus17-Aug-09 15:37 
GeneralRe: Oh, get over it! Pin
JoseMenendez21-Aug-09 11:25
JoseMenendez21-Aug-09 11:25 
JokeA missing option Pin
Nemanja Trifunovic17-Aug-09 5:03
Nemanja Trifunovic17-Aug-09 5:03 
GeneralRe: A missing option Pin
Abhishek Sur20-Aug-09 22:31
professionalAbhishek Sur20-Aug-09 22:31 
Generalvar is ugly PinPopular
Huisheng Chen17-Aug-09 3:08
Huisheng Chen17-Aug-09 3:08 
GeneralRe: var is ugly Pin
Xmen Real 17-Aug-09 3:35
professional Xmen Real 17-Aug-09 3:35 
GeneralRe: var is ugly Pin
Todd Smith17-Aug-09 13:04
Todd Smith17-Aug-09 13:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.