"Extension Method" is a static method of static classes. We can call extension methods just like calling methods of other class instances.
Description and call of extension methods
For example, I want to add a static toint32 method for the string type and convert the string type to int32:
Public static class exmethod {public static int32 toint32 (this string s) {return int32.parse (s );}}
Note:
1. Add the this keyword before the first parameter to specify this extension method.
2. The extension method must be static and the class must be static.
3. The class of the extension method cannot be a "nested class" (this class is nested in another class)
Calling an extension method is simple and looks like calling a static method of a common class instance:
String S = "1234"; S. toint32 ();
In the Visual Studio programming environment, the extension method gives a special prompt:
Extended method priority
The priority of the conventional object instance method lies in itsDeclaration FormAndWhen the declared form of the called function is matchedHigher than the extension method.
The extension method is a very useful concept. When developers want to expand a sealed class, there is a way.