For the specified type Extension Method:
Definition class Class1:
Public static class Class1 // must be a static class and cannot contain Constructors
{
/// <Summary>
/// Return the length of the array separated by "$" in the specified string
/// </Summary>
/// <Param name = "value"> string value </param>
/// <Returns> integer </returns>
Public static int ArrayListLenght (this string value)
{
Int len = 0;
If (value. IndexOf ("$")> = 0)
{
Len = value. Split ($). Length;
}
Return len;
}
}
Page call:
Protected void Page_Load (object sender, EventArgs e)
{
String sValue = "bbsdfdfd $ ssbbsdfdfd $ ss ";
Int count = sValue. ArrayListLenght ();
Response. Write ("value:" + count );
}
Output: Value: 3
The above only lists the "string" type extension methods. Similarly, You can provide other types of extension methods. Here, you can also use the data type as a generic processing method.