C# 3.0 – What’s new?

Hello! everyone. This is festive time here in India. Yesterday we all celebrated Diwali, festival of light. I must tell you that lot of things have changed, things like playing with crackers, going out with friends and watching the way people decorated their houses using lights and ribbons. Yesterday, after having our Diwali prayer I just watched a movie (CHUCK) @ home and slept at around 11. Nothing new for me and it turned out to be yet another holiday. I wish things remained the same way as they were before.

Now let’s talk technology. Microsoft have another a new set of features to C# in its third avatar. There is complete list available at MSDN, but I just wanted to add my comments to it as I study new features one by one. What I am planning is, I’ll study one new feature everyday, post it here with my comments.

  1. Implicitly Typed Local Variables
    • Type is inferred by the expression used to initialize the variable
    • Only applicable to local variable
    • Variable declared using keyword ‘var
    • There should be no Type with name ‘var‘ defined in scope. Only then type inferring will work
    • We should initialize the variable where we declaring it
    • Initialized must be an expression.
    • Local variable declaration should not include multiple variables
    • Initializer should not refer to variable itself
    • Some Examples: [ is Same as ]
      var i = 5; int i = 5;
      var s = “Hello”;
      string s = “Hello”;
      var d = 1.0;
      double d = 1.0;
      var numbers = new int[] {1, 2, 3};
      int[] number = new int[]{1,2,3};
    • Some incorrect use of var:
      var x; // Error, no initializer to infer type from
      var y = {1, 2, 3}; // Error, collection initializer not permitted
      var z = null; // Error, null type not permitted
      var u = x => x + 1; // Error, lambda expressions do not have a type
      var v = v++; // Error, initializer cannot refer to variable itself
    • for, foreach and using (resource acquisition) can also use var. Like,
      int[] numbers = { 1, 2, 3, 4, 5 };
      foreach (var n in numbers) { //Do some thing }
      Why do we need to use var? Everything should be Type Strict. I think this will impact performance as compiler will use some kind of intelligence to find out variable type and it will surely take up some time. This is no scripting language…man this is C#. It will just complicate things even more and add to huge list of keywords that we already have like sealed, virtual, override, abstract, new, internal etc. I don’t see any use of this so called added feature.
      Please let me know your opinions.

Currently Listening To: Shadow of the day-LINKIN PARK
~eNjOy cOdinG~



  1. For his or her supplementation comprising nutritional supplements, enzymes along with
    essential nutrient elements together can help you to wipe off night bags under eyes.
    Do not forget to you recognize family group on this .
    very good Peer to peer web interfaces! Though you still might not want it given that DeLonghi espresso machine house owners
    hold the costly cost akin to return back available. Move non-chemical come across one near!
    A wide range of gluten free pastries pots and pans trust in a person's entire flour to be able to an food.

    Here is my web-site; turkish coffee automatic


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s