If statement will execute a block of code if the given condition is true. The if statement checks a Boolean expression and executes the code based on if the expression is true< /p>
if(condition){
//code to be executed
}
using System;
public class Program
{
public static void Main()
{
int number = 10;
if (number % 2 == 0)
{
Console.WriteLine(number+ " is an even number");
}
}
}
10 is an even number
using System;
public class Program
{
public static void Main()
{
int a = 20, b = 10;
if (a > b)
{
Console.WriteLine("a is greater than b");
}
if (a < b)
{
Console.WriteLine("a is less than b");
}
if (a == b)
{
Console.WriteLine("a is equal to b");
}
}
}
a is greater than b