In C#, Extension methods can be identified by this logo. Extension methods can be defined in C# in a separate .cs file.
The extension method is called an instance method but is actually a static method. The instance pointer "this" is a parameter, and you must specify the "this" keyword before the appropriate parameter you want the method to be called upon.
The difference between a regular static method and an extension method is that, in a static method, we first provide the class name and then we call the method. In the extension method, the "this" keyword is in the parameter list. You can directly call this by a variable.
Create an Extension method.
- Open Visual Studio
- "File" ">>" New >> "Web Site..."
- Select "ASP.NET Empty Web Site", then click "OK"
- Add a new WebForm
- Add a new Class
ExtentionMethods.cs