C# Statements


This entry is part 7 of 10 in the series C# Getting Started

The statements in C# are similar to those of C and C++. A statement is a source code instruction describing a type or telling the program to perform an action. A simple statement is terminated by a semicolon.

The code listing below has two simple statements. The first one declares and initializes an integer variable. The second simple statement displays the value of the variable on the console.

A block is a sequence of zero or more statements enclosed by a matching set of curly braces; it acts as a single syntactic statement. You can create a block from the set of two statements in the following example by enclosing the statements in matching curly braces, as shown. Blocks are not terminated by a semi-colon.

{
   int myVariable = 7;
   System.Console.WriteLine("The value of myVariable is {0}", myVariable);
}
Series Navigation<< C# IdentifiersC# Numeric Format Strings >>