The extension method is used to add new methods in the existing class or the structure without modifying the source code of the original type. Special permission from the original type or re-compiling it isn’t required.
In .NET, an extension method is a static method that adds new functionality to an existing type without altering its structure, directly modifying the source code of the type, or creating a new derived type. It’s a way to extend the behavior of classes or interfaces without modifying their source code.
The correct answer to the question “What is the extension method for a class?” could be:
“An extension method in .NET is a static method that is declared within a static class. It must be visible within the namespace where it’s intended to be used. Extension methods are invoked as if they were instance methods of the extended type. To define an extension method for a class, you need to declare a static method within a static class, and the first parameter of the method should be of the type you want to extend, preceded by the ‘this’ keyword.”