Syntax for If - else

  if (condition)
  {
              Statements
              .
              .
  }
  else
 {
              Statement
              .
              .
              .
  }

 

Example:- 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CABasics
{
    class IfElseExample7
    {
        static void Main(string[] args)
        {
            int N;
            Console.WriteLine("Enter any Number either 1 or 2");
            N = Convert.ToInt32(Console.ReadLine());
            if (N == 1)
            {
                Console.WriteLine("Hai");

            }
            if (N == 2)
            {
                Console.WriteLine("Hellow");
            }
            else
            {
                Console.WriteLine("You Have not entered either 1 or 2");
            }
            Console.ReadLine();
        }
    }
}

































Output :-










No comments:

Post a Comment