Array of Class

  • Thread starter Thread starter Max André Bündchen
  • Start date Start date
M

Max André Bündchen

Hi,

I must design a method that receive a Control object and return a single
value if it is a TextBox object, another value if it is a ComboBox object
and so on.

If I try a "if-else-if" loop, this will be very unhappy! Can I use a foreach
to make that? How declare and create the array for use in the operator "is"
(for test a Control, like "cont is TextBox")?

Thanks,

Max
 
Hello Max,
you can use switch/case for this purpose. something like,

int val = -1;
switch(typeof(obj))
{
case System.Windows.Forms.TextBox:
//assign the val;
break;
case System.Windows.Forms.CheckBox:
//assign another value to val
break;
 
Can you explain further why you need to do this? Writing a routine like
this seems to do nothing more than duplicate the behaviour of the
..GetType() method on the object. Perhaps if we knew what your larger
problem was, we could suggest a different way to solve it.
 
Back
Top