C# if statement | c# if | if c# - c# - c# tutorial - c# net

C# If Statement
What is if statement in C# ?
- In C#, an if statement consists of a Boolean expression followed by one or more statements.

Syntax:
if (condition)
{
condition statement is true;
}

if statement in c#
C# Sample Code - C# Examples:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace wikitechy_if_condition
{
class Program
{
static void Main(string[] args)
{
int n = 5;
if (n <= 5)
{
Console.WriteLine("wikitechy says this condition is true");
}
Console.ReadLine();
}
}
}
Code Explanation:

- Here n = 5 is an integer variable value as 5.
- Here, if (n <= 5) expression specifies the n =5 is less than, or equal to 5 i.e., (5 <= 5), which executes the statement "wikitechy says this condition is true".
Sample C# examples - Output :

- Here the statement executes the if condition by printing the statement "Wikitechy says this condition is true".