title: C# Switch expressions returning different result
body: <p>I've switched to C# 8 on one of my projects. And I've been moving all of my <code>switch</code> statements to expressions. However I found out that my project started working differently and I've found out that it was because of the <code>switch</code> expression. Lets get this code for example</p>
  
  <pre><code>class Program
  {
      public enum DataType
      {
          Single,
          Double,
          UInt16,
          UInt32,
          UInt64,
          Int16,
          Int32,
          Int64,
          Byte
      }
  
      static void Main(string[] args)
      {
          dynamic value1 = 5;
          dynamic value2 = 6;
  
          var casted = CastToType(value1, DataType.Int16);
          var casted1 = CastToTypeExpression(value2, DataType.Int16);
  
  
          var type = casted.GetType(); // Int16
          var type1 = casted1.GetType(); // Double
          var bytes = BitConverter.GetBytes(casted); // byte arr with 2 el =&gt; [5, 0] &lt;- expected behavior 
          var bytes1 = BitConverter.GetBytes(casted1); // byte arr with 8 el =&gt; [0, 0, 0, 0, 0, 0, 24, 64]
      }
  
      public static dynamic CastToType(dynamic value, DataType type)
      {
          switch (type)
          {
              case DataType.Byte:
                  return (byte)value;
              case DataType.Double:
                  return (double)value;
              case DataType.Int16:
                  return (short)value;
              case DataType.Int32:
                  return (int)value;
              case DataType.Int64:
                  return (long)value;
              case DataType.Single:
                  return (float)value;
              case DataType.UInt16:
                  return (ushort)value;
              case DataType.UInt32:
                  return (uint)value;
              case DataType.UInt64:
                  return (ulong)value;
              default: throw new InvalidCastException();
          }
      }
  
      public static dynamic CastToTypeExpression(dynamic value, DataType type)
      {
          return type switch
          {
              DataType.Byte =&gt; (byte)value,
              DataType.Double =&gt; (double)value,
              DataType.Int16 =&gt; (short)value,
              DataType.Int32 =&gt; (int)value,
              DataType.Int64 =&gt; (long)value,
              DataType.Single =&gt; (float)value,
              DataType.UInt16 =&gt; (ushort)value,
              DataType.UInt32 =&gt; (uint)value,
              DataType.UInt64 =&gt; (ulong)value,
              _ =&gt; throw new InvalidCastException(),
          };
      }
  }
  </code></pre>
  
  <p>I've wrote the result as a comment, but tl;dr when classic switch is used casting the value returns the value in the expected Type, but when switch expression is used it returns type of "Double", resulting to different <code>byte[]</code> when getting the bytes of the value.</p>
  
  <p>What's the difference between the two? What do I miss?</p>