How to find out if an object is of <type> or a decendant of <type>

Posted by Vaccano on Stack Overflow See other posts from Stack Overflow or by Vaccano
Published on 2010-04-16T03:59:32Z Indexed on 2010/04/16 4:03 UTC
Read the original article Hit count: 259

Filed under:
|

I have the following code:

foreach (var control in this.Controls)
{

}

I want to do something like control.Hide() in there. But the items in the this.Controls collection are not of type Control (they are Object).

I can't seem to remember the safe way to cast this to call hide if it is really of type Control and do nothing otherwise. (I am a transplanted delphi programmer and I keep thinking something like control is Control.)

© Stack Overflow or respective owner

Related posts about c#

Related posts about c#3.0