Extension Methods & its Advantages in C#
Extension Methods in C#
Extension Methods were introduced in c# 3.0. These methods are helpful in adding methods to the types which already existed i.e without creating a derived type via inheritance, methods can be added to existing type. In short functionality of existing type is extended.
Creation and Usage of Extension Method
Extension method can be defined as static method with static class where first parameter in this method is used with “this” modifier and type of this parameter is of the type that is extended.
Program Demonstrating Usage of Extention Methods
First create a blank solution named “ExtmethodExample” in visual studio 2015. Create a project Class Library named as “Extmethod”.
Now create another project console application named “ExtendingExtmethod” in “ExtmethodExample” solution and include the reference of class library created above in this project.
Read more about Extension Methods & its Advantages in C# visit FindNerd.