Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




C# - BOOLEAN


Boolean represents just two values, i.e. True or False.


Boolean Data Type


A bool Data Type can accept only true or false.


Example :



public class MyApplication
{
    public static void Main(string[] args)
    {
     	bool x = true;
   	    bool y = false;
	    System.Console.WriteLine(x);
   	    System.Console.WriteLine(y);
    }
}


Output :



  True
  False

So, in the above code, we have created a variable named x of Boolean data type and initialised it with value True.


bool x = true;
C_Sharp


And created one more variable called y of Boolean data type and initialised it with value False.


bool y = false;
C_Sharp


But if we want to initialise a Boolean type variable with anything other than true/false, it would end up with an error.