I currently have an extension method on System.Windows.Forms.Control like this:
public static void ExampleMethod(this Control ctrl){ /* ... */ }
However, this method doesn’t appear on classes derived from Control, such as PictureBox. Can I make an extension method that appears not only in Control, but for classes derived from Control, without having to do an explicit cast?
You must include the using statement for the namespace in which your extensions class is defined or the extension methods will not be in scope.
Extension methods work fine on derived types (e.g. the extension methods defined on
IEnumerable<T>in System.Linq).