C# – First steps with C# and .NET – part 047.

Extension methods enable you to “add” methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are static methods, but they’re called as if they were instance methods on the extended type. see the official website.
Let’s see one simple example:

In this example, you can see three extension methods: one is the two methods Where and Select and one is defined by my class ExtensionMethods.
The result of this source code in C# is:

You can see the running source code in C# online at this online tool.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.