Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error CS0133
Collapse the table of content
Expand the table of content

Compiler Error CS0133

The expression being assigned to 'variable' must be constant

A const variable cannot take as its value an expression that is not constant. For more information, see Constants (C# Programming Guide).

The following sample generates CS0133:

// CS0133.cs
public class MyClass
{
   public const int i = c;   // CS0133, c is not constant
   public static int c = i;
   // try the following line instead
   // public const int i = 6;

   public static void Main()
   {
   }
}

Community Additions

ADD
Show:
© 2015 Microsoft