title: c# 8.0 switch expression return type and null value
body: <p>I'm trying to understand how C# 8.0 switch expressions work and have got several questions.</p>
  
  <ol>
  <li>Why is it not possible to use <code>null</code> value in the default case? The compiler throws <code>Cannot convert null to 'int' because it is a non-nullable value type</code> error.</li>
  <li>Why is it trying to convert the null value to <code>int</code> whereas the function's return type is 'double?'?</li>
  </ol>
  
  <p>Here is the function I'm playing with:</p>
  
  <pre><code>public static double? SwitchFunction(int x) =&gt;
      x switch
      {
          1 =&gt; 1,
          _ =&gt; null
      };
  </code></pre>