Using "as" and expecting a null return
<p>For example.  Lets say we have a stackpanel on a form.  Its full of both Grids and Labels.  I want to loop through all the Grids and do some operation on them but leave the Lables intact.  At the moment I am doing it this way.</p>

<pre><code>foreach(UIElement element in m_stacker.Children)
{
    Grid block = element as Grid;
    if(block != null)
    {
      //apply changes here
    }
}
</code></pre>

<p>So i'm using the fact that "as" returns null if it cannot cast into the required type.  Is this an ok thing to do or is there a better solution to this problem?</p>
