Should I prefer the 'is' or 'as' operator?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/496096/casting-vs-using-the-as-keyword-in-the-clr">casting vs using the &#39;as&#39; keyword in the CLR</a>  </p>
</blockquote>



<pre><code>foreach (MyClass i in x)
{
        if (i is IMy)
        {
                IMy a = (IMy)i;
                a.M1();
        }
}
</code></pre>

<p>or</p>

<pre><code>foreach (MyClass i in x)
{
        IMy a = i as IMy;
        if (a != null)
        {
                a.M1();
        }

}
</code></pre>
