title: Casting an object which could be null
body: <pre><code>DateTime? testDate = (DateTime?)arrayOfObjects[dateObject];
  </code></pre>
  
  <p>Does that code look ok? I attempted to use the <code>as</code> operator but I got the 'non-nullable' error. What I'm trying to say is that the object I'm choosing from the array is either <code>DateTime</code> or a <code>null DateTime</code> but either can be assigned to testDate.</p>
  
  <p>Doesn't feel right doing it this way, I think I'm missing something obvious.</p>
  
  <p>EDIT: I suppose it's the same as the way I could've adapted the <code>as</code> in the following way:</p>
  
  <pre><code>DateTime? testDate = arrayOfObjects[dateObject] as DateTime?;
  </code></pre>
  
  <p>Is either line of code the best way of handling potential nulls?</p>