Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0150 

Error Message

A constant value is expected

A variable was found where a constant was expected. For more information, see switch (C# Reference).

The following sample generates CS0150:

// CS0150.cs
namespace MyNamespace
{
   public class MyClass
   {
      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:
         }
      }
   }
}

Community Additions

ADD
Show:
© 2015 Microsoft