We have static methods:
String someString = "someString"; Console.Writeline(someString); Console.ReadKey(); Can we add a static method to the Console class via extension methods? For example:
Console.DoSomething(); We have static methods:
String someString = "someString"; Console.Writeline(someString); Console.ReadKey(); Can we add a static method to the Console class via extension methods? For example:
Console.DoSomething(); No you can not. Extension methods require passing instances of classes to them (those that are passed by the first parameter and are preceded by the this modifier, it is to these instances that the "extension" is applied), while the Console is a static class.
Source: https://ru.stackoverflow.com/questions/625896/
All Articles
Consoleclass? - Vadim Prokopchukstatic void Click(this Cursor cursor) { }, provided that theCursornot a static class. - Vadim ProkopchukCursorEx, in which you define the necessary methods. With instance methods such a trick without static methods would be more difficult. - VladD