title: Why does pattern matching on a nullable result in syntax errors?
body: <p>I like to use <code>pattern-matching</code> on a <code>nullable int</code> i.e. <code>int?</code>:</p>
  
  <pre><code>int t  = 42;
  object tobj = t;    
  if (tobj is int? i)
  {
      System.Console.WriteLine($"It is a nullable int of value {i}");
  }
  </code></pre>
  
  <p>However, this results in the following syntax errors:</p>
  
  <ul>
  <li><a href="https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs1003" rel="noreferrer" title="Compiler Error CS1003 | Microsoft Docs">CS1003: Syntax error, ';'</a>,</li>
  <li><a href="https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs1525" rel="noreferrer" title="Compiler Error CS1525 | Microsoft Docs">CS1525: Invalid expression term ')'</a>,</li>
  <li><a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0103" rel="noreferrer" title="Compiler Error CS0103 | Microsoft Docs">CS0103: The name 'i' does not exist in the current context</a>.</li>
  </ul>
  
  <p>'i)' is marked with a red squiggly line.</p>
  
  <p>The expression compiles when using the old operator <code>is</code>:</p>
  
  <pre><code>int t = 42;
  object tobj = t;    
  if (tobj is int?)
  {
      System.Console.WriteLine($"It is a nullable int");
  }
  
  
  string t = "fourty two";
  object tobj = t;
  if (tobj is string s)
  {
      System.Console.WriteLine($@"It is a string of value ""{s}"".");
  }
  </code></pre>
  
  <p>Also works as expected.</p>
  
  <p><em>(I'm using <a href="/questions/tagged/c%23-7.2" class="post-tag" title="show questions tagged &#39;c#-7.2&#39;" rel="tag">c#-7.2</a> and tested with both <a href="/questions/tagged/.net-4.7.1" class="post-tag" title="show questions tagged &#39;.net-4.7.1&#39;" rel="tag">.net-4.7.1</a> and <a href="/questions/tagged/.net-4.6.1" class="post-tag" title="show questions tagged &#39;.net-4.6.1&#39;" rel="tag">.net-4.6.1</a>)</em></p>
  
  <p>I thought it had something to with operator precedence.  Therefore, I have tried using parenthesis at several places but this didn't help.</p>
  
  <p>Why does it give these syntax errors and how can I avoid them?</p>