Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the difference between bool and Boolean in c#?
.
can we use new with Boolean?

bool B=true;
Console.WRILTElINE("tHE BOOL VALUE IS{0}:",B);
so it is display <b>True</b> why?
Posted

bool is an alias for System.Boolean just as int is an alias for System.Int32. See here[^]. To check a full list of aliases see here[^].
 
Share this answer
 
v2
Hello,
Boolean is a datatype that will return u only two values either true or false the code which you have displayed will defiantely return a true value because u have declared a Boolean value named B and initialized a value true to it and displayed b if u wana try some examples with boolean then my friend heres the right code for you

C#
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            bool b = true;

            int a = 10;
            if (a < 1)
            {
                Console.WriteLine("value of b is :"+b);
            }
            else
            {
                b = false;
                Console.WriteLine("value of b is :" + b);
            }
        }
    }
}


just try changing value for integer variable "a" and u will see the trick...
Now coming to the first part of your question thats difference between bool and Boolean

my friend bool is an alias for System.Boolean jsut like int is an alias for System.Int32 thats it :)

please do rate my answer once u find it useful

Thanks & Regards
Radix :rose:
 
Share this answer
 
v2
There is NO difference whatsoever.
You may use either bool or Boolean with exactly the same results.
 
Share this answer
 
Hi
The difference between bool and Boolean is as follows

bool is basic data type and Boolean is an object type

Boolean is an class which wraps the bool type because in the object oriented technology,we have to represent in the form of classes and object so that for every data type we have an class type.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900