title: Casting dynamic to int succeeds but 'as int?' returns null
body: <p>I am confused by some code results using <code>dynamic</code>.</p>
  
  <p>I am parsing some JSON in C# using the Newtonsoft json.net libraries. The JSON string ends like this:</p>
  
  <pre><code>}],"Result":{"820":1,"821":1,"822":2,"823":0}}
  </code></pre>
  
  <p>and so I set up a class to contain the parsed JSON:</p>
  
  <pre><code>public class Poll
  {
      public Answer[] Answer { get; set; }
      public dynamic Result { get; set; }
  }
  </code></pre>
  
  <p>and then parse my JSON string with this line</p>
  
  <pre><code>var poll = JsonConvert.DeserializeObject&lt;BallotsharePoll&gt;(json);
  </code></pre>
  
  <p>and then this code to delve into the dynamic object:</p>
  
  <pre><code>if (poll.Result["820"] != null)
  {
      var votes = (int)(poll.Result["820"]).Value;
      result[i] = votes;
  }
  </code></pre>
  
  <p>This works. But my original code used int? and the line </p>
  
  <pre><code>var votes = (poll.Result["820"]).Value as int?;
  </code></pre>
  
  <p>which fails as shown in the watch window here:</p>
  
  <p><img src="https://i.stack.imgur.com/7tO1C.png" alt="VS2013 watch window screenshot"></p>
  
  <p>This shows that </p>
  
  <ul>
  <li>the dynamic value of <code>poll.Result["820"]</code> is <code>{1}</code>, </li>
  <li>the value of <code>(int)(poll.Result["820"]).Value</code> is <code>1</code>, </li>
  <li>but the value of <code>(poll.Result["820"]).Value as int?</code> is <code>null</code></li>
  </ul>
  
  <p><strong>QUESTION:</strong> Why does <code>as int?</code> return <code>null</code> while casting to <code>int</code> results in <code>1</code>?</p>
  
  <p>I would rather use <code>int?</code> to cover the case where the dynamic value cannot be coerced into an <code>int</code>.</p>