Extension methods are static methods that can be invoked using instance method syntax. In effect, extension methods make it possible to extend existing types and constructed types with additional methods.
Extension methods are declared by specifying the keyword this as a modifier on the first parameter of the methods. Extension methods can only be declared in non-generic, non-nested static classes.
The following is an example of a static class that declares two extension methods:
|
It becomes possible to invoke the extension methods in the static class Extensions using instance method syntax:
Instance method syntax
|
Code:
Reversed UML model: |
The value is created to Tag extend in «C#Params»: