Compiler error · error CS1002
; expected
A statement didn't end where the compiler expected it to. The single most common C# error — and its most useful property: the real mistake is usually on the line before the one the error points at.
See it happen
int x = 5
Console.WriteLine(x);
Read the error carefully: it points to line 2 — but the missing semicolon is at the end of line 1. The compiler only discovers the problem when it sees Console where a ;, an operator, or a } should be. So the rule when hunting CS1002:
Go to the reported line, then look at the end of the line above it.
int x = 5;
Console.WriteLine(x);
What actually needs a semicolon?
Statements end with ;. Blocks — the things with { … } — don't. That's the whole rule:
int total = 0; // declaration statement → ;
for (int i = 1; i <= 3; i++) // for(...) itself → no ;
{
total += i; // inside the block → each statement gets ;
} // closing } → no ;
if (total > 2) // no ;
{
total++; // yes ;
} // no ;
Console.WriteLine(total); // yes ;
The classic triggers
1. Returning mid-thought
int Add(int a, int b)
{
return a + b // forgot the ; after the return value
}
Console.WriteLine(Add(1, 2));
2. Method call on its own line
Console.WriteLine("working…")
Console.WriteLine("never reached");
3. The cascade — one missing ; produces five errors
Without a ;, the compiler glues line 1 and line 2 into one giant nonsense expression, then reports the first place it gets confused. Fix the FIRST error, recompile, and the rest often evaporate. Beginners fix the last error first; the compiler reads top to bottom, and so should you.
Frequently asked
How do I fix error CS1002 in C#?
Without a semicolon the compiler glues two lines into one giant expression and only trips where the syntax can't continue — one line below the real mistake. That's also why one missing semicolon often produces a cascade of errors: fix the FIRST error and recompile.
Why does CS1002 report the wrong line?
undefined
Cousin error: CS1513 ( } expected )
The sibling of the missing semicolon is the missing brace. Same debugging rule, rotated: the error points at the line where the compiler ran out of code — walk the braces backward from there.
Checklist
- Error on line N → check the end of line N−1 first.
- Every declaration, assignment,
return,break,continue, and standalone call gets a;. if/for/while/switchheaders and closing}never do.- Many errors at once? Fix the first one, recompile — cascades collapse.