Compiler Error CS1059
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.
Example
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
}
}
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for