Object reference not set to an instance of an object. - DefaultValue
<p>Say I have three classes A, B and C and they are nested in such a manner that I can access C through B through A (ie. A.B.C). If I'm trying to access a simple property of C, say Id type int, and I haven't instanciated a new instace of B in A (or C in B) I would get an 'Object reference not set to an instance of an object.' error.</p>

<p>What I'd like to know is if there is a simple way of saying get me A.B.C.Id and if you can't becuase something is null along the way give me a default value.</p>

<pre><code>var myId = A.B.C.Id &lt;some operator&gt; -1;
</code></pre>

<p>At the moment I'm doing something like this and it just feels horrible.</p>

<pre><code>var myId = A == null ? -1 : A.B == null ? -1 : A.B.C == null ? -1 : A.B.C.Id;
</code></pre>
