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();
}
}
Second is more preferable as you cast 1 time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With