C# if statement | c# if | if c# - c# - c# tutorial - c# net
![C# If Statement](https://wikitechy.com/tutorials/csharp/img/c-sharp-images/csharp-if-statement.gif)
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.
![c sharp if statement string](https://wikitechy.com/tutorials/csharp/img/c-sharp-images/c-sharp-if-statement-string.png)
Syntax:
if (condition)
{
condition statement is true;
}
![if statement in c#](https://wikitechy.com/tutorials/csharp/img/c-sharp-images/c-sharp-if-statements.gif)
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:
![c sharp if operator](https://wikitechy.com/tutorials/csharp/img/c-sharp-images/c-sharp-if-operator.png)
- 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 :
![nested if else in c sharp](https://wikitechy.com/tutorials/csharp/img/c-sharp-images/nested-if-else-in-c-sharp.png)
- Here the statement executes the if condition by printing the statement "Wikitechy says this condition is true".