Code Blocks
A free lesson from Swipe Coding · C#, level 1 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
Curly braces { } group multiple statements together into a shared block in C#. A block marks a clear beginning and a clear end — for example the body of a class or the body of a method.
class Program
{
static void Main()
{
Console.WriteLine("Hello, C#!");
}
}Blocks can be nested inside one another, similar to a box inside another box. The block of the Main() method lies completely inside the block of the class — it starts later and ends earlier than the class block.
class Program { // Start of class block
static void Main() { // Start of method block
Console.WriteLine("Hello, C#!");
} // End of method block
} // End of class blockWhat are curly braces { } used for in C#?
Every opening brace { must eventually have a matching closing brace }. If one is missing, the compiler can't tell where a block ends and reports an error — even if the rest of the code is correct.
Every opening curly brace { needs a matching closing brace }.
As a reminder: the class itself is a block, the Main() method is another block inside it, and the individual statements from the last lesson sit inside these blocks. That's how everything in a C# program fits together.
The block of the Main() method lies ____ the block of the class.
Keep your streak going in Swipe Coding
Swipe through every level of C# on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →