Extension methods
There are many ways to extend a class, and if you have the source code for the class, inheritance is the best way to add functionality to an object. If you do not have source code, you can use the extension method.
Public class student{ publicint age=; Public Static class studentextention { publicstaticvoid addage ( This Student stu,int i) { + = i; }} }
The extended method must be a static method and must be placed in a static class. For an extension method, the first parameter is the type to be extended and must be placed after the This keyword. In an extension method, you can access all public methods and properties of the type being extended.
When an extension method is called, it must be an instance object call.
If the extension method is the same as the signature of a method in the class, the extension method is never called, and the instance method already in the class takes precedence.
extension methods in C #