Monopoly: C# 3.0 Edition

Posted on December 05, 2007  |  

Posted in Apologetics

7 comments

Coming to a Toys R Us near you:

C# 3.0 community cheat: the var keyword

7 comments

Josh Stodola
on December 5, 2007

LOL great analogy!


Jon
on December 6, 2007

I was just reading the spec for this ... I'm unable to come up with a situation where someone would use 'var' instead of explicitly defining the type. Can you give a real-world example of where it might be useful, by chance?


Milan Negovan
on December 7, 2007

I drew these cards in good humor :)

On a more serious note, the 'var' keyword does have valid uses. Anonymous types are one such example. The whole idea is to not declare a class upfront, but have the compiler infer its structure. My worry is that people will be tempted to use 'var' haphazardly with trivial cases. Hence the 'get out of jail free' analogy.


Daniel Steigerwald
on December 7, 2007

Keyword var is absolutely useful. Try to get type name of anonymous type :)

var someTemporallyDataShapingObject = new {
page.ID, page.InMenu, page.Order, page.ParentID, page.PublishedPage, page.Site, page.SiteID, page.State, page.Title, page.UrlTitle
}; // get only properties I need e.g. for JSON serialization.

Without var keyword, how could you reference anonymous type?
And, after one year of programming in javascript, I absolutely prefer
narrative code, than old C# bloated, a lot of indended and chatty code which do almost nothing, but spans over half screen ;)

Many new C# 3.0 construct allow you to write tight code.
Compare:
Dictionary>> result = new Dictionary>>();

with

var result = new Dictionary>>();

Why to insist seeing double ;) when its obvious what will be placed on left side :)


Daniel Steigerwald
on December 7, 2007

Hi Milan, it seems your editor strips not only HTML tag :)


Milan Negovan
on December 7, 2007

*cough* Yes, it thinks generics are HTML tags, too. ;)


Vectorpedia
on January 6, 2008

I love your Get of Jail card........lol


Leave a comment

  •