views:

344

answers:

5

Maybe I live in a bubble, or am just too new, but I was wondering if anyone else has noticed the heavy use of 'var' to declare variables instead of a specific type in many of the MVC examples by Microsoft? Is there a purpose for this, or is it the "in" thing to do now, or just personal style?

Curiously, Jeff

A: 

All of the above.

OJ
A: 

Anonymous Types are your friends.

RandomNoob
So from this link it looks like I need to learn more about LINQ.
Jeff Keslinke
var != Anonymous Types
James Curran
@James: No, but anonymous types would be impossible without var.
GalacticCowboy
@James : Show me where I implied var == anonymous types, I simply posted a link to give the op a point of reference.
RandomNoob
+2  A: 

Jared Parsons talked about this in his blog I don't agree with his conclusions (as my comment there indicates), but this article should explain why it's used so much.

Harper Shelby
+1  A: 

All MVC Videos are maded in speedy way(also not always they using Unit test or placing bussiness logic in controlers). This is not because they are bad programmers, or "var" is cool, but because they want to quickly show some cool new features, and typing full name twice is not what they want to show.

AlfeG
A: 
Skittles
Not exactly. A "var" variable is still strongly-typed to its *actual* type, the system just figures it out instead of making you type it out explicitly. This is not the same concept as a Variant, or passing stuff around as an "object".
GalacticCowboy
Good point GC. http://www.interact-sw.co.uk/iangblog/2005/09/23/varisntobject
Skittles
I understand that people have every right to mark an answer down but I am just wondering what benefit it is in this case. I made a mistake, acknowledged it and post a link to a correct explanation. I understand now why users simply won't post anymore for fear of the scorn of 'Gurus'
Skittles
@Skittles: the point of downvoting is so that incorrect or poor answers are readily recognizable as such. If the best answer, for whatever reason, only gets 1 up vote, and all the others are at 0, then it's hard to say that any of the others are really bad. Down votes help clarify that.
Harper Shelby
@Harper: Thanks you for taking the time to explain. I will update the answer that I gave to reflect this.
Skittles