Possible Duplicate:
casting vs using the 'as' keyword in the CLR
foreach (MyClass i in x)
{
if (i is IMy)
{
IMy a = (IMy)i;
a.M1();
}
}
or
foreach (MyClass i in x)
{
IMy a = i as IMy;
if (a != null)
{
a.M1();
}
}