Use an if statement to execute a block of code in CSharp

Description

The following code shows how to use an if statement to execute a block of code.

Example


//from   w w  w .  j av  a  2 s .  c o m
public class MainClass{
  public static void Main(){
    int smallNumber = 5;
    int bigNumber = 100;

    if (bigNumber < smallNumber)
    {
      System.Console.Write(bigNumber);
      System.Console.Write(" is less than ");
      System.Console.Write(smallNumber);
    }
    else
    {
      System.Console.Write(smallNumber);
      System.Console.Write(" is less than ");
      System.Console.Write(bigNumber);
    }
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    C# Language »




C# Hello World
C# Operators
C# Statements
C# Exception