Extension method: Difference between revisions

Content deleted Content added
The versioning problem: the entire thing can be stated in one line which I am going to add. this thing was how-to-ish and uncited anyway
Extension methods: add the info back in summarized form.
Line 23:
</source>
 
===Extension methods===
The new language feature of extension methods in C# 3.0, however, makes the latter code possible. This approach requires a static class and a static method, as follows:
<source lang="csharp">
Line 39:
The major difference between extension methods and normal, static helper methods is that static methods calls are [[Polish_notation|prefix notation]], whereas extension methods calls are in [[Infix_notation|infix notation]]. This leads to more readable code when the result of one operation is used for another operation.
 
;With static methods: <source lang="csharp>HelperClass.Operation2(HelperClass.Operation1(x, arg1), arg2)"</source>
 
With extension methods: "x.Operation1(arg1).Operation2(arg2)"
 
;With extension methods: <source lang="csharp">x.Operation1(arg1).Operation2(arg2)"</source>
 
In the current implementation, a member method with the same name as an extension method shadows the latter and makes it inaccessible. The IDE ([[Microsoft Visual Studio|Visual Studio]]) also does not warn about the naming conflict.
 
==See also==