Monopoly: C# 3.0 Edition
Posted in Apologetics
Coming to a Toys R Us near you:

7 comments
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
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. ;)

Josh Stodola
on December 5, 2007
LOL great analogy!