I want to cast both MenuItem objects and Button control objects to an object type of whose ‘Tag’ property I can reference.
Is there such an object type?
E.g.
void itemClick(object sender, EventArgs e) { Control c = (Control)sender; MethodInvoker method = new MethodInvoker(c.Tag.ToString(), 'Execute'); method.Invoke(); }
Except this fails – ‘Unable to cast object type ‘System.Windows.Forms.MenuItem’ to type ‘System.Windows.Forms.Control’
What can replace Control in this example?
Use ‘as’ operator.