If_ Else Statement in C#
if...else Statement can be followed by an optional else statement, which executes when the boolean expression is false.
Program
using System;
namespace if_Statement {
class Program {
static void Main(string[] args)
{
int x = 25; /* Here x value is 25 */
/* check the boolean condition using if statement */
if (x > 45) /*Here condition x is greater then 45 so it is false */
{
/* if condition is true then print the following statement */
Console.WriteLine("yes x value is 25");
}
else /*this code will execute*/
{
/* if condition is false then print the following */
Console.WriteLine("No x value is 25.");
}
Console.ReadLine();
}
}
Output- No x value is 25.
if...else Statement can be followed by an optional else statement, which executes when the boolean expression is false.
Program
using System;
namespace if_Statement {
class Program {
static void Main(string[] args)
{
int x = 25; /* Here x value is 25 */
/* check the boolean condition using if statement */
if (x > 45) /*Here condition x is greater then 45 so it is false */
{
/* if condition is true then print the following statement */
Console.WriteLine("yes x value is 25");
}
else /*this code will execute*/
{
/* if condition is false then print the following */
Console.WriteLine("No x value is 25.");
}
Console.ReadLine();
}
}
Output- No x value is 25.