In C# 1.0 - the methods were belonging to a class. That means the methods were defined within the body of the class. C# v2.0 introducing partial classes - the methods making up a class could be defined in more than one place. At compile time they are all collected together. Extension methods are new to C# v3. Extension methods are a powerful new language feature that ensures the code abstraction and increase the code re usability
http://aamimoheeb.blogspot.in/2012/05/how-to-write-extension-method.html
HOW to define extension method?as per msdn
1. Define a static class with appropriate access modifier.
2. Implement the extension method as a static method with at least same visibility of the containing class.
3. The first parameter of the method specifies the type that the method operates on. It must be preceded with the 'this' modifie
HOw to call extension Methods ?
as per msdn
1. In the calling code, add a using directive to specify the namespace that contains the extension method class.
2. Call the method as if they were instance methods on the type. You do not need to specify the first parameter because it represents the type on which the operator is being applied, and the compiler already knows the type of your object. You only have to provide arguments for parameters 2 through n
So, extension methods are defined as static methods but are called by using instance method syntax. There first parameter specifies which type the method operates on, and the parameter is preceded by the this modifier. Extension methods are only in scope when you explicitly import the namespace into your source code with using directive
http://aamimoheeb.blogspot.in/2012/05/how-to-write-extension-method.html
HOW to define extension method?as per msdn
1. Define a static class with appropriate access modifier.
2. Implement the extension method as a static method with at least same visibility of the containing class.
3. The first parameter of the method specifies the type that the method operates on. It must be preceded with the 'this' modifie
HOw to call extension Methods ?
as per msdn
1. In the calling code, add a using directive to specify the namespace that contains the extension method class.
2. Call the method as if they were instance methods on the type. You do not need to specify the first parameter because it represents the type on which the operator is being applied, and the compiler already knows the type of your object. You only have to provide arguments for parameters 2 through n
So, extension methods are defined as static methods but are called by using instance method syntax. There first parameter specifies which type the method operates on, and the parameter is preceded by the this modifier. Extension methods are only in scope when you explicitly import the namespace into your source code with using directive
Comments
Post a Comment