Tracks
/
C#
C#
/
Syllabus
/
If Statements
If

If Statements in C#

24 exercises

About If Statements

An if statement can be used to conditionally execute code. The condition of an if statement must be of type bool. C# has no concept of truthy values.

The most common way to do this in C# is by using an if/else statement:

int x = 6;

if (x == 5)
{
    // Execute logic if x equals 5
}
else if (x > 7)
{
    // Execute logic if x greater than 7
}
else
{
    // Execute logic in all other cases
}
Edit via GitHub The link opens in a new window or tab

Learn If Statements

Practicing is locked

Unlock 10 more exercises to practice If Statements