# What is a statement?

A statement is an instruction. A statement can have variables, constants, functions or expressions in it.

# Example 1

Console.Write("Hello");
1

This line is a statement. It instructs to print "Hello".

# Example 2

Console.WriteLine("");
1

This line is a statement. It instructs to print a newline.

# Example 3

Console.WriteLine("Hello World");
1

This line is a statement. It instructs to print "Hello World" and a newline.

# Example 4

num = 2 * 10;
1

This line is a statement. It instructs to assign result of "2 * 10" to variable num.

# Example 5

string eg = "Hello";
1

This line is a statement. It declares a string variable eg and initializes it to "Hello".

TIP

In C#, statements end with a semicolon ;.

# Example 6

for loop is a statement.

for(int i = 0; i < 10; i++)
{
}
1
2
3

It instructs to run the loop 10 times. Notice this statement does not end at ;.

# Example 7

if (num == 2)
{
}
1
2
3

This code is also a statement, but it does not end at ;.

TIP

In C#, statements blocks are defined using curly braces {}.

Last Updated: Apr 30, 2020, 8:50 PM