4.2.The if-else statement

An if-else statement allows you to take a multiple selection, when the boolean expression checking true, the statement(s) in the block immediately following the if statement are executed. However, when the boolean expression checking false, the statements in the block following the else keyword are executed.

Listing 3-1:

using System;

namespace CSharp
{
        class if_else_Selection
        {
                static void Main(string[] args)
                {
                        float score;
                        Console.Write("Enter Score: ");
                        score = float.Parse(Console.ReadLine());
                        if (score >= 50)
                                Console.WriteLine("Passed");
                        else
                                Console.WriteLine("Failed");
                        Console.ReadKey();
                }
        }
}

Example 1: Windows Forms Application:

Example 2: Windows Forms Application: (More than two conditions)

Yes No Suggest edit
Suggest Edit