This documentation is archived and is not being maintained.

Compiler Error CS0150

A constant value is expected

A variable was found where a constant was expected.

The following sample generates CS0150:

// CS0150.cs
namespace x
{
   public class a
   {
      public static void Main()
      {
         int i = 0;
         int j = 0;

         switch(i)
         {
            case j:   // CS0150, j is a variable int, not a constant int
            // try the following line instead
            // case 1:
         }
      }
   }
}
Show: