title: When to use 'as' and when to use 'is' in C#
body: <blockquote>
    <p><strong>Possible Duplicate:</strong>
    <a href="https://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>
  
  
  
  <p>As someone new to C# I was wondering if there is any important difference between this:</p>
  
  <pre><code>object o = SomeFunction();
  if (o is MyClass)
  {
      MyClass myObject = (MyClass) o;
      myObject.MyFunction();
  }
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>object o = SomeFunction();
  MyClass myObject = o as MyClass;
  if (myObject != null)
      myObject.MyFunction();
  </code></pre>
  
  <p>When is one preferred over the other? In the code I work with, both seem to be used randomly.</p>