title: C# switch statement limitations - why?
body: <p>When writing a switch statement, there appears to be two limitations on what you can switch on in case statements.</p>
  
  <p>For example (and yes, I know, if you're doing this sort of thing it probably means your <a href="https://en.wikipedia.org/wiki/Object-oriented_programming" rel="noreferrer">object-oriented</a> (OO) architecture is iffy - this is just a contrived example!),</p>
  
  <pre><code>  Type t = typeof(int);
  
    switch (t) {
  
      case typeof(int):
        Console.WriteLine("int!");
        break;
  
      case typeof(string):
        Console.WriteLine("string!");
        break;
  
      default:
        Console.WriteLine("unknown!");
        break;
    }
  </code></pre>
  
  <p>Here the switch() statement fails with 'A value of an integral type expected' and the case statements fail with 'A constant value is expected'.</p>
  
  <p>Why are these restrictions in place, and what is the underlying justification? I don't see any reason why the switch statement <em>has</em> to succumb to static analysis only, and why the value being switched on has to be integral (that is,  primitive). What is the justification?</p>