title: Weird switch behavior in .NET 4
body: <p>I have a problem understanding what's causes the compilation error in the code below:</p>
  
  <pre><code>static class Program
  {
      static void Main()
      {
          dynamic x = "";
          var test = foo(x);
  
          if (test == "test")
          {
              Console.WriteLine(test);
          }
  
          switch (test)
          {
              case "test":
                  Console.WriteLine(test);
                  break;
          }
      }
  
      private static string foo(object item)
      {
          return "bar";
      }
  }
  </code></pre>
  
  <p>The error I get is in <code>switch (test)</code> line:</p>
  
  <pre><code>A switch expression or case label must be a bool, char, string, integral, 
  enum, or corresponding nullable type.
  </code></pre>
  
  <p>Intellisence shows me that foo operation will be resolved on runtime, which is fine because I'm using a dynamic type as a param. However I don't understand how <code>if</code> condition compiles fine when switch doesn't.</p>
  
  <p>Code above is just simplified version of what I have in my application (VSTO) which appeared after migrating the app from VSTO3 to VSTO4 when one method in VSTO was changed to return <code>dynamic</code> type values instead of <code>object</code>.</p>
  
  <p>Can anyone give me an explanation what's the problem. I know how to resolve it but I'd like to understand what's happening.</p>