Method extension in VS2008 and VS2010

Neeks
Posted by Neeks under C# category on | Views : 2496
We are used to use the static method of the class.
public class CommonClass
{
public CommonClass
{

}
public static string ReverseString(string stringToReverse)
{
//Code to reverse the string
}

}



Calling the static method.

MessageBox.Show(CommonClass.ReverseString("DotNetFunda"));


Now, we move to method extension

public static class ExtensionClass
{
public static string ReverseString(this string str)
{
//Code to reverse the string
}
}


Calling
MessageBox.Show("DotNetFunda".ReverseString());

Comments or Responses

Login to post response