bool keyword in C#

C# bool keyword: Here, we will find out about the bool keyword in C#, what is bool keyword, how to utilize it in C#?

C# bool keyword

In C#, bool is a keyword which is utilized to announce a variable that can store Boolean qualities genuine or bogus. bool keyword is an assumed name of System.Boolean.

It involves 1 byte (8 bits) in the memory.

Syntax:

    bool variable_name = value;

There are just two potential qualities that can be doled out to a bool variable 1) genuine or 2) bogus

C# code to show example of bool keyword

Here, we are announcing a bool variable answer, introducing it with the worth genuine and printing its worth, type, and size of a bool type variable.

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //bool variable declaration
            bool answer = true;

            //printing value
            Console.WriteLine("answer: " + answer);
            //printing type of variable
            Console.WriteLine("Type of answer: " + answer.GetType());
            //printing size of a bool 
            Console.WriteLine("Size of a bool variable: " + sizeof(bool));

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output:

answer: True
Type of answer: System.Boolean
Size of a bool variable: 1

Leave a Comment

error: Alert: Content is protected!!