C#: Adding extension methods to a base class so that they appear in derived classes

前端 未结 5 841
旧时难觅i
旧时难觅i 2021-01-04 10:02

I currently have an extension method on System.Windows.Forms.Control like this:

public static void ExampleMethod(this Control ctrl){ /* ... */ }
5条回答
  •  孤城傲影
    2021-01-04 10:24

    An extension method will actually apply to all inheritors/implementors of the type that's being extended (in this case, Control). You might try checking your using statements to ensure the namespace that the extension method is in is being referenced where you're trying to call it.

提交回复
热议问题