Question : How can I make a method that targets Control and MenuItem

Hi there,

I there a way I can declare a method in .net compact framework that accepts an argument that can be of type "Control" or "MenuItem"?

Answer : How can I make a method that targets Control and MenuItem


Both Control and MenuItem classes inherits System.ComponentModel.Component
class, so your method could be like:

using System.ComponentModel;

public void MyMethod(Component component)
{
   if(component is Control)
   {
         Control c = component as Control;
          // use c
    }
    else if(component is MenuItem)
    {
         MenuItem m = component as MenuItem;
         // use m
      }
}
Random Solutions  
 
programming4us programming4us