Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
if statement | Control Structures
C# Basics
course content

Course Content

C# Basics

C# Basics

1. Getting Started
2. Dealing with Data Types
3. Control Structures
4. Loops
5. Arrays
6. Methods

bookif statement

An if-statement, also known as Conditional Statement, is a method of executing a block of code based on a condition. The syntax of an if-statement is the following:

It takes an expression and executes the code block if the expression is true.

For-example:

cs

main

copy
12345678910111213141516
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { Console.WriteLine("Before Conditional"); if(10 > 9) { Console.WriteLine("10 is greater than 9"); } Console.WriteLine("After Conditional"); } } }

In case the condition is false the code block is ignored:

cs

main

copy
12345678910111213141516
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { Console.WriteLine("Before Conditional"); if(10 > 10) { Console.WriteLine("10 is greater than 9"); } Console.WriteLine("After Conditional"); } } }
What is the output of the following code:

What is the output of the following code:

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 5
We're sorry to hear that something went wrong. What happened?
some-alt