| Extension methods is a new feature of C# 3.0 that allows you to enhance an existing framework class by adding a new method to it without modifying the actual code of that class.Suppose you want to calculate the 4th power of an integer. For that you will have to square it two times. So instead of that you can create an Extension Method on integer
public static class ExtensionExample
{
public static int powerfour(this int myNumber)
{
return myNumber ;
}
}
Extension Methods are created in a static class and the Extension Method must be defined as static as shown above. The this keyword preceding the first parameter creates an extension method that applies to the type of that parameter. So here an Extension Method called Cube to the int type is created. | | |