Can a cast from object to class ever fail when both are exactly the same?
<p>If I have the following code</p>

<pre><code>object o = new Building(4, "something");
</code></pre>

<p>And I attempt the following</p>

<pre><code>if(o.GetType() == typeof(Building))
    Building buildingCast = o as Building;
</code></pre>

<p>What could go wrong? I want to make sure that <code>buildingCast</code> can never be null from a problematic cast. Is there any way at all that cast could fail? Even something obscure? </p>

<p>The reason I ask is that I am cleaning up a test project and I am trying to weed out redundant code. There are checks against <code>buildingCast</code> possibly being null...</p>

<pre><code>if(buildingCast == null)
    etc
</code></pre>

<p>...but we cannot reach the code in the if statement.</p>
