C# Tutorial – C# Statements


Every application executes a set of actions. In C# applications they are called C# statements and they are separated by ; char. Statements are executed in sequence unless a statement says different (jump statements / conditional statements). Here are some examples of simple C# statements:

  • Declare variable int i;
  • Assign value i = 5;
  • Call a method System.Console.WriteLine();

Block of code

A series of code can be considered a single statement as well. It have to be included inside {}  brackets. It’s also called block of code.

    int a = 3;
    int b = 5;
    int sum = a + b;

Embedded / nested statements

A statement can also contain other statement. Perfect example is if  statement.

if (a > 3)
    b = 3;
    b = a;

In the above example b = 3;  and b = a;  are C# statements and are embedded in if  statement.

Unreachable statements

C# compiler can do a simple analysis of your code. It can detect a piece of code that will never be executed. Following example will produce a warning.

const bool notTrue = false;
if (notTrue)


Here you can find more C# statement examples.



Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

One thought on “C# Tutorial – C# Statements