Use if else to complete the condition check in CSharp

Description

The following code shows how to use if else to complete the condition check.

Example


     using System;
//  w w  w.  jav a  2 s  .  c o  m
     public class MainClass
     {
         static void Main()
         {
             int valueOne = 10;
             int valueTwo = 20;

             Console.WriteLine("Testing valueOne against valueTwo...");
             if ( valueOne > valueTwo )
             {
                 Console.WriteLine(
                     "ValueOne: {0} larger than ValueTwo: {1}",
                     valueOne, valueTwo);
             }       // end if
             else
             {
                 Console.WriteLine(
                     "Nope, ValueOne: {0} is NOT larger than ValueTwo: {1}",
                     valueOne, valueTwo);
             }       // end else

         }           // end Main
     }               // end class

The code above generates the following result.





















Home »
  C# Tutorial »
    C# Language »




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