static - Extensions method replaces the standard method in C# -


there ways use extension methods signatures of standard methods extension (without explicit appeal static class)? example:

public class foo {     public override string tostring()     {         return "own";     } }  public static class extensionsmethods {     public static string tostring(this foo foo)     {         return "extensions";     } }  class program {     static void main()     {         var foo = new foo();                     console.writeline(foo.tostring()); // "own" printed     } } 

can use extensions-tostring version without explicit appeal class extensionsmethods

no, cannot this. extension method not used if method same signature available:

you can use extension methods extend class or interface, not override them. extension method same name , signature interface or class method never called.

see extension methods (c# programming guide) binding extension methods @ compile time details.

there might inheritance or decorator alternative solution you.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -