Boolean Data Type in C# Programming Language

Rumman Ansari   Software Engineer   2019-03-05   6087 Share
☰ Table of Contents

Table of Content:


Boolean

A boolean data type is used to work with Boolean values of true and false. In C#, the datatype is denoted by the Boolean keyword. Below is an example of this datatype can be used.

 

In our example, we will define a Boolean variable called 'status.' We will then assign a boolean value to the variable and then display it accordingly.

 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program
  { 
   static void Main(string[] args) 
   {
    Boolean status=true;
    Console.Write(status);
    
    Console.ReadKey();
   }
  }
}

Code Explanation:-

  1. The boolean data type is specified to declare a Boolean variable called 'status.' The variable is then assigned a value of true/false.
  2. Finally the console.write function is used to display the Boolean value to the console.

If the above code is entered properly and the program is executed successfully, the output will be displayed.

Output:

true

From the output, you can clearly see that the Boolean variable which equals true was displayed in the console