Understanding the Boolean Data Type in C# Programming: A Comprehensive Guide

Rumman Ansari   Software Engineer   2024-10-01 04:18:00   6569  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

Boolean Type in C#:

Data Type Size (bytes) Values Description
bool 1 true, false Represents a boolean value (true or false)

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;
 
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




Stay Ahead of the Curve! Check out these trending topics and sharpen your skills.