Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, April 5, 2009 2:48 PM
Hi!
I have a simple question. What the difference with Boolean and bool?
When should I use this two?
In my case I want a method to return true or false.. which one should I use?
All replies (8)
Monday, April 6, 2009 1:10 AM âś…Answered
Hi,
bool is an alias for System.Boolean like int is an alias for System.Int32.
bool comes in dark blue is because it is a C# keyword, and Boolean in light blue is because it's a type (inbuild application types and user-defined types).
If you like my post mark it as ANSWER.
Regards,
sunil
Sunday, April 5, 2009 3:33 PM
Are you working with C# or VB?
C#
In C#, bool is a type. In the example below, we make the variable myvariable to be a bool.
bool myvariable = true;
The word Boolean is an adjective. There are two Boolean values, true and false.
reference: http://msdn.microsoft.com/en-us/library/c8f5xwh7(VS.71).aspx
VB
I'm assuming at this point that you are a C# person because you asked about both words. I am a C# person too, but I try to keep my VB knowledge not too far behind my C# knowledge (many people are VB). I looked it up for VB.NET and found:
From http://msdn.microsoft.com/en-us/library/wts33hb3.aspx,
The above suggests the word Boolean is used as the type, as well as the adjective. Just to make sure, I tested it with the VB code below:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim itistrue As Boolean = True
Dim itisfalse As Boolean = False
Label1.Text = itistrue.ToString() + " " + itisfalse.ToString()
End Sub
Sunday, April 5, 2009 3:33 PM
Hi,
there is a thread about it here:
http://stackoverflow.com/questions/134746/what-is-the-difference-between-bool-and-boolean-types-in-c
You would need bool.
JC
Sunday, April 5, 2009 7:42 PM
From the C# standard
...reserved words are simply aliases for predefined struct types in the System namespace
bool is a reserved word of the C# language which is an alias for System.Boolean (eg they are the same thing). You can use either System.Boolean or bool in your code and you will get the same result.
Sunday, April 5, 2009 11:32 PM
Boolean is a variable type in C# and you can use it for True/false.
Monday, April 6, 2009 12:49 AM
All the above answers are correct. But if you are a true C# lover, try using bool. Whereas if you think your application much interact with VB.NET or you are designing a library use System.Boolean. I have seen many automated code generator who use System.Boolean while creating code.
Soumen,India
Saturday, March 6, 2010 6:55 PM
Here is a post which explains the difference between a bool and a boolean
http://dotnetrobert.com/?q=node/22
Hope you find it useful.
Sunday, March 7, 2010 3:00 AM
As said a few times on this thread. bool is a keyword that is an alias for System.Boolean. They're essentially the same thing. Keep in mind that if your application interacts with VB.net, bool will be interpreted by VB.net as Boolean.
in regards to the "any true c#" comment.. /facepalm.