In this code snippet, we will take a look at extension methods in C#.
If you have a class that you don’t own or is sealed you won’t be able to add anything to it. In such cases, you can use extension methods which will be “glued” on to the class. This enables you to add your code to a class without modifying it or creating a new derived class.
Let’s have a look at the code below to see how to implement an extension method.