Compiler Error CS1059

Visual Studio 2008

The operand of an increment or decrement operator must be a variable, property or indexer.

This error is raised when you try to increment or decrement a constant value. It can also occur if you try to increment an expression such as (a+b)++.

To correct this error

  • Make the variable non-const.

  • Remove the increment or decrement operator.

  • Store the expression in a variable, and then increment the variable.

The following example generates CS1059 because i is a constant, not a variable, and E is an Enum type, whose elements are also constant values.

// CS1059.cs
    class Program
        public enum E : sbyte
            a = 1,
            b = 2

        static void Main(string[] args)
            const int i = 0;
            i++;            // CS1059
            E test = E.a++; // CS1059

Community Additions