Compiler error · error CS0131
The left-hand side of an assignment must be a variable, property or indexer
Assignment (=) stores a value into something. If the left side has no storage — a constant, a literal, a computed expression — there's nowhere to put it, and the compiler says so.
Cause 1: assigning to a constant
const int Max = 100;
Max = 200; // CS0131: 'const' means it can NEVER change — that's the deal
const is a compile-time promise: this value is baked in, forever. If the value genuinely needs to change later, it isn't a constant:
int max = 100; // a variable…
Console.WriteLine(max);
max = 200; // …can be reassigned freely
Console.WriteLine(max);
The middle ground in real code is static readonly — set once at startup, immutable after, but not compile-time.
Cause 2: assigning into an expression
int x = 5;
x + 1 = 10; // 'x + 1' computes a value — there's no box to store 10 into
This is almost always a flipped comparison or a mistyped target. What was meant?
int x = 5;
bool isTen = (x + 1) == 10; // comparing? that's '==', and either side may be an expression
Console.WriteLine(isTen);
int x = 5;
x = x + 1; // storing back INTO the variable: left side is just 'x'
Console.WriteLine(x);
What the left side CAN be
| Left side | Stores into | Example |
|---|---|---|
| variable | the variable | x = 5; |
| property | the property's storage | obj.Name = "Ada"; |
| indexer | that slot | arr[0] = 5; / dict["k"] = v; |
| field | the object's field | dog.Age = 3; |
Everything else — literals (5 = x;), constants, method calls, arithmetic — produces a value rather than holding one, and can never sit on the left.
Frequently asked
What does error CS0131 mean in C#?
Never — const is a compile-time promise that the value never changes. If the value must change later, declare it as a regular variable (or static readonly for set-once-at-startup semantics).
Can I assign to a const in C#?
undefined
Checklist
- Left of
=: a plain name, a.Member, or an[index]. Nothing else. =stores;==compares. One character, opposite meaning.constcan't be reassigned by design — use a variable if it must change.x = x + 1is legal (store the computed value back intox);x + 1 = …is not.