Tuesday, February 10, 2009

Extension method

Extension method is a new feature available in .NET 3.0 framework. Extension Method enable a variety of useful scenarios, and help make possible the really powerful LINQ query framework that is being introduced with .NET as part of the VS 2008 / .NET 3.5 release. The usage is shown in the below snapshot.

Beware to simply insert the this keyword before the int argument in the Double() helper method, which make the extension method possible, then we can indeed type side.Double(). In fact, the advantage of doing this is that intellisense will help you by showing the method in the dropdown when you type a dot after the variable and also makes something more readable. The extension method should be static and class as well.
However extension method should be avoided in cases where encapsulation breaks.


Suresh Nayak said...

Good post buddy. Keep it up :-)