Create a gist now

Instantly share code, notes, and snippets.

anonymous /gist:5450899
Created Apr 24, 2013

What would you like to do?

Personally, I only ever use var for anonymous types. Basically, when I have to use var rather than an explicit type.

I dislike the use of var for implicitly inferring types which can just as easily be explictly declared, i.e. :

// Yes, it's obvious that i is an int!
var i = 10;

// But why not use "int i = 10;".  Just as many characters to type!
int i =10;

Also, there are some situations where typing of the var is not obvious, at least not to me, i.e.:

var q = SomeFunkyMethodThatReturnsSomething();

Hmm.. Now I have to look up SomeFunkyMethodThatReturnsSomething in order to find out it's return type before I can know what q will be. Yes, intellisense can help, but I shouldn't have to rely on that, nor should I have to perform additional steps in order to know what type q is.

Here's another (admittedly contrived example) of where this kind of typing can be confusing:

double d = 0;
var e = 0;

I don't know about you, but this makes me have to do a double-take (excuse the pun!). At first glance, due to the "code noise" if you like, it's not immediately obvious what e is here. I have to stop and think before realizing that e is an int.


This comment has been minimized.

Show comment Hide comment

DaniilDemidov Jul 14, 2016

I agree!

I agree!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment