More on the .NET 2.0 and .NET 3.5 Comparison

In my demo last week I extended a string class; I am pleased to say that after some ( quick ) investigation as predicted the calls to the class are identical.

To explain extensions we can use the following code

class Fred {

   string MyStringMethod ( string s ) {

      // do something

   }

}

string x = Fred.MyStringMethod(x);

Using extensions we can change the definition of the method MyStringMethod to use this

   string MyStringMethod ( this string s )

this allows us to call it in a more friendly manner

string x = x.MyStringMethod();

as if it were a member of string.

When looking at the code generated there is No difference in the invocation i.e., it always calls Fred.MyStringMethod. the only change to code is the attribute added to the MyStringMethod

[Extension] attribute which has been attend to the method which shows that it is an extension method.

All I can say is I think that the language designers at Microsoft have done another great seamless job on adding features.

I have not been able to add the attribute by hand at this point.

Boss.