C# Extension Methods

C# Code Snippets Extension Methods


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.


Resulting output:


Leave a Reply

Your email address will not be published.

The following GDPR rules must be read and accepted:
This form collects your name, email and content so that we can keep track of the comments placed on the website. For more info check our privacy policy where you will get more info on where, how and why we store your data.

Advertisment ad adsense adlogger