if statement with bool variable : boolean Data Type « Data Type « C# / CSharp Tutorial






using System;

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");  
    }
  }
}
You should see this
Will you see this?
Statement 1
Statement 2








2.2.boolean Data Type
2.2.1.The bool Type
2.2.2.Output a boolean variable with Console.WriteLine
2.2.3.bool values in if statement
2.2.4.if statement with bool variable
2.2.5.Declare 3 bools on a single line
2.2.6.Using ToString() to Convert to a string
2.2.7.Generic and nongeneric versions of the CompareTo method for Boolean type