C# nested if-else Statement :

nested if-else Statement :

Sometimes the programming logic in a program or an application needs to be represented by multiple if-structures contained in each other. We call them nested if or nested if-else structures.

Example :

  1. /* Description: simple nested if-else program */
  2. using System;
  3. namespace DemoProgramming
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int first = 5,second = 3;
  10. if (first == second)
  11. {
  12. Console.WriteLine("These two numbers are equal.");
  13. }
  14. else
  15. {
  16. if (first > second)
  17. {
  18. Console.WriteLine("The first number is greater.");
  19. }
  20. else
  21. {
  22. Console.WriteLine("The second number is greater.");
  23. }
  24. }
  25. Console.ReadKey();
  26. }
  27. }
  28. }

Output :

C Sharp Language simple nested if-else program

Computer Science Engineering

Special Notes

It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.

CSE Notes