Skip to main content
CSharpUniversity ASP.NET and C# lessons

The search runs entirely in your browser over the published lesson list.

Blocks of code and the semicolon

C# is strict about punctuation. Two characters, the semicolon and the brace, carry most of the meaning about where one instruction ends and the next begins.

The semicolon ends a statement

A statement is one instruction. A semicolon tells the compiler that the instruction is complete. Leave it out and the compiler keeps reading, then complains about the line below.

The brace groups statements

Braces wrap a block of statements that belong together, such as the body of a method or the branch of a condition.

C#
if (isReady)
{
    Prepare();
    Start();
}

Why indentation is not enough

Indentation is for humans. The compiler ignores it. Braces are what the compiler obeys, so the two must agree or the code will do something other than what it looks like.

Habit. Let the editor indent as you type. If the indentation looks wrong, the braces are probably wrong too, and that is a useful early warning.

With statements and blocks understood, you are ready for the decisions and loops track.

New lessons by email

Leave your address and get a short note whenever a fresh lesson is published. No account needed and you can stop at any time.

Thank you. Your address has been noted in this browser session. Connect a mailing service to deliver the notes for real.