Keywords are the words in a language that are used for some internal process or represent some predefined actions. bool is a keyword that is used to declare a variable which can store Boolean values true or false. It is an alias of System.Boolean.
Bool Keyword occupies 1 byte (8 bits) in the memory. There are only two possible values of bool i.e. true or false.
Syntax:
bool variable_name = value;
Example:
Input: true
Output: answer: False
Size of a byte variable: 1
Input: false
Output: Type of answer: System.Boolean
answer: True
Size of a bool variable: 1
Example 1:
// C# program for bool keyword using System; using System.Text; class GFG { static void Main(string[] args) { // bool variable declaration bool answer = false; // to print value Console.WriteLine("answer: " + answer); // to print size of a bool Console.WriteLine("Size of a bool variable: " + sizeof(bool)); } } |
Output:
answer: False Size of a bool variable: 1
Example 2:
// C# program for bool keyword using System; using System.Text; namespace geeks { class GFG { static void Main(string[] args) { // bool variable declaration bool answer = true; // to print type of variable Console.WriteLine("Type of answer: " + answer.GetType()); // to print value Console.WriteLine("answer: " + answer); // to print size of a bool Console.WriteLine("Size of a bool variable: " + sizeof(bool)); // hit ENTER to exit Console.ReadLine(); } } } |
Output:
Type of answer: System.Boolean answer: True Size of a bool variable: 1
Recommended Posts:
- How to implement is functionality without using is keyword in C#
- C# | this Keyword
- C# | finally keyword
- C# | as Operator Keyword
- C# | is Operator Keyword
- Is vs As operator keyword in C#
- Static keyword in C#
- typeof Operator Keyword in C#
- Invoking an overloaded constructor using this keyword in C#
- Difference between readonly and const keyword in C#
- LINQ | Let Keyword
- uint keyword in C#
- byte Keyword in C#
- decimal keyword in C#
- char keyword in C#
- sbyte Keyword in C#
- float keyword in C#
- double Keyword in C#
- void Keyword in C#
- short keyword in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

