Use if statement with bool variable in CSharp

Description

The following code shows how to use if statement with bool variable.

Example


using System;//from  w  ww . j a v  a 2s. c  o  m

public class MainClass {
  public static void Main( ) {
    bool boolValue1 = true;
    bool boolValue2 = false;


    if( boolValue1 ) 
      Console.WriteLine("You should see this");

    if( boolValue2 )
      Console.WriteLine("You should not see this");

    if( boolValue1 && !boolValue2 )
      Console.WriteLine("Will you see this?");

    if( boolValue1 ) {
      Console.WriteLine("Statement 1");
      Console.WriteLine("Statement 2");  
    }
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var