Suppose there is a simple argument function of the form

public static void Toggle(Panel p) { p.Visible = !p.Visible; } 

Is it possible to set an undefined argument with no type, so that it applies an action to any given element, be it a panel, a table or a label?

  • one
    public static void Toggle(Control p) { ... - Igor
  • Thank! Add as an answer, not a comment, confirm the answer with a green check mark =) - Kodek

1 answer 1

The listed types have a common ancestor - Control , in System.Web.UI , System.Windows.Forms or System.Windows.Controls :

 public static void Toggle(Control p) { p.Visible = !p.Visible; }