On Mar 11, 2:40 pm, Darren <Dar...@nospam.nospamwrote:
if ( control is ICustomControl )
{
....
}
Ron wrote:
I have a situation where I need to test if a Control implements from a
specific Interface to avoid an invalid cast exception:
foreach (Control ctrl in this.Controls)
{
// Need to test to see if ctrl inherits interface ICustomControl here
ICustomControl control = (ICustomControl)ctrl;
}
Thanks!
Ron
Alternately, he can do this:
foreach (Control ctrl in this.Controls)
{
// Need to test to see if ctrl inherits interface ICustomControl here
ICustomControl control = ctrl as ICustomControl;
if ( control != null ) {
// do something
}
}