If there is an if statement inside another if statement, it’s known as C# Nested-if statement. In this statement, you can use one if or else if statement inside another if or else if statement(s).
If the value of test-expression is true, the true block of statements will be executed in this type of construct. The false block of statements will be executed if the value of test-expression is false. In either instance, control will be immediately transferred to the statements outside the If block following the execution.
We’ll set a value for a variable and develop a programme to see if the number is less than 10 or larger than ten.
Syntax for C# Nested-if statement
The if-else construct is demonstrated in the following programmes:
// nested-if statement in C# using System; public class csharp { public static void Main(String[] args) { int x = 5; if (x == 5) { // Nested - if statement // executed if statement if its true if (x < 10) Console.WriteLine("x is smaller than 10"); else Console.WriteLine("x is greater than 15"); } } }