Posts

Showing posts with the label #C #ExtensionMethod

C# Extension Method

Image
It is a new feature that has been added in C# 3.0 which allows us to add new methods into a class without editing the source code of the class i.e. if a class consists of a set of members in it and in the future if you want to add new methods into the class, you can add those methods without making any changes to the source code of the class. Extension methods can be used as an approach to extending the functionality of a class in the future if the source code of the class is not available or we don’t have any permission in making changes to the class. Before extension methods, inheritance is an approach that is used for extending the functionality of a class i.e. if we want to add any new members to an existing class without making a modification to the class, we will define a child class to that existing class and then we add new members in the child class. In the case of an extension method, we will extend the functionality of an existing class. In this case, we will create a new cl...