Basic C# Syntax

C# is a block – structured language, meaning statements are part of a block of code. These blocks, which are delimited with curly brackets ( { and } ), may contain any number of statements, or none at all. Note that the curly bracket characters do not need accompanying semicolons. For example, a simple block of C# code could take the following form:

{
 < code line 1, statement 1 > ;
 < code line 2, statement 2 >
 < code line 3, statement 2 > ;
}

Here the < code line x , statement y > sections are not actual pieces of C# code; this text is used as a placeholder where C# statements would go. In this case, the second and third lines of code are part of the same statement, because there is no semicolon after the second line. The following simple example uses indentation to clarify the C# itself. This is actually standard practice, and in fact VS automatically does this for you by default. In general, each block of code has its own level of indentation, meaning how far to the right it is. Blocks of code may be nested inside each other (that is, blocks may contain other blocks), in which case nested blocks will be indented further:

{
   < code line 1 > ;
{
   < code line 2 > ;
   < code line 3 > ;
}
   < code line 4 > ;
}