C Sharp for Beginners/Making Decisions

From Wikibooks, open books for an open world
Jump to navigation Jump to search

If Statement:[edit | edit source]

The if statement in c# is so simple like other languages. The syntax for if statement is:

if(condition){
// Statements
}

Here is condition we can check some expression for true or false. For example 5 > 4 is true but 4 > 5 is false.

if(5 > 4){
Console.WriteLine("Yes five is still greater than 4");
}

Else part:[edit | edit source]

In the else part if if condition we can give statements which will execute if condition is false.

if(5 > 4){
Console.WriteLine("Yes five is still greater than four");
} else {
Console.WriteLine("Oh No! five is now no longer greater than four");
}