C# if Statement

In C# if statement is used to control the flow of a program. If Statement is used to separate the logics based on certain condition. When if Condition becomes true the code inside it perform its execution.

Following is the Syntax of if Statement.

if (condition)
    statement

Let's understand the flow of if statement with an image.

C# if statement

Example

Try It
using System;
 
namespace TutorialsLeader
{
    public class MyFirstClass
    {
        static void Main()
        {
            int a = 1, b = 20;
 
            if (a == 1)
                Console.WriteLine("The value of a is one");
 
            if (b > a)
                Console.WriteLine("b is greater than a");
 
            Console.ReadKey();
        }
    }
}

Let's learn about the if-else statement in C# in the next section.