Now Repeat After Me, Var Isn't an Object

0 comments suggest edit

Leave it to Ian to cut through the crap and give a very clear and detailed account of what exactly the new var keyword in C# does.

When reading through blogs, mailing lists, and newsgroups, you can encounter a lot of noise from people who are just looking for something to rant about without actually taking the time to understand what they’re talking about. This can be about the most annoying thing in the world.

So if you caught yourself asking:

What’s wrong with “Object”?

I encourage you to read Ian’s post.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

4 responses

  1. Avatar for Sharp as a Marble
    Sharp as a Marble September 23rd, 2005

    Smells a lot like 'variant' in good ol' ASP.



    I wonder if it has the same overhead as variant did?

  2. Avatar for Haacked
    Haacked September 23rd, 2005

    Heh heh.. you're busting my chops.



    If you read the article, you'll notice that the var keyword is statically typed using type inference. In otherwords, it's compile time evaluated. In other words, there is no overhead.

  3. Avatar for Niels Hansen
    Niels Hansen September 23rd, 2005

    Think of it more like the Dim statment in Visual Basic



    Why should you have to tell the compiler twice what the variable is. The compiler should be smart enough to know what your asking.



  4. Avatar for Haacked
    Haacked September 23rd, 2005

    Excellent point!