You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$10
For Premium members:
This article explains Extension methods, a new existing feature of C# 3.0.
Introduction
This article explains Extension methods, a new existing feature of C# 3.0. This feature is available in 3.0 and higher versions of C#. An Extension method is very important and very special for programming developers.An Extension method is special for the class design. Why we need Extension Methods
Using an Extension method we can use another class method without changing functionality. But it is very compulsory that an Extension method be defined in a top-level static class.Generally in our programming we saw that there are two classes, a parent class and a child class in our program. The child class inherits the method of a parent class. it can change the functionality of the parent class method. But in an Extension method it must not be required to change the functionality of another method without having a sub class. A drawback exists in extension methods, they cannot be used to override an existing method.
Specification of an Extension Method
An Extension method is a very cool and new feature. We can say this is an instance method. This Extension method is a Static method of a static class. This allows us to add a new method for a predefined method. It increases the functionality of a predefined method.An Extension method can use another method without inheritance and without changing the source code. In the Extension method we are using the "this" modifier. It is applied as the first parameter and the parameter extends the functionality of this method without changing a parent class method.
Example of extension Method
Full code of extension Method
Output
The SOLID Principles