bool values in if statement : boolean Data Type « Data Type « C# / CSharp Tutorial






using System; 
 
class Example { 
  public static void Main() { 
    bool b; 
 
    b = false; 
    Console.WriteLine("b is " + b); 
    b = true; 
    Console.WriteLine("b is " + b); 
 
    // a bool value can control the if statement 
    if(b) 
       Console.WriteLine("This is executed."); 
 
    b = false; 
    if(b) 
       Console.WriteLine("This is not executed."); 
 
  } 
}
b is False
b is True
This is executed.








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