views:

12559

answers:

9

What is the difference between Bool and Boolean types in C#?

+12  A: 

I don't believe there is one.

bool is just an alias for System.Boolean.

bhinks
+6  A: 

They are one in the same. bool is just an alias for Boolean.

MagicKat
+2  A: 

One is an alias for the other.

itsmatt
+43  A: 

bool is an alias for System.Boolean just as int is an alias for System.Int32. See a full list of aliases here.

HTH, Kent

Kent Boogaart
From the above link microsoft says The C# type keywords and their aliases are interchangeable But why we need Aliases, From my point of view Boolean is more meaningful then bool and Int32 is more meaningful then int then why aliases ???
Asim Sajjad
@asim: laziness? It's less typing and avoids the need to import System. Personally, I prefer the aliases. Typing "int" is far quicker than typing "Int32".
Kent Boogaart
+4  A: 

They are the same. Boolean helps simplify conversion back and forth between C# and VB.Net. Most C# programmers tend to prefer 'bool', but if you are in a shop where there's a lot of both VB.Net and C# then you may prefer Boolean because it works in both places.

Joel Coehoorn
+2  A: 

As has been said, they are the same. There are two because bool is a C# keyword and Boolean a .Net class.

Carra
So wouldn't bool be better for cross-platform compatibility?
Jess
A: 

bool is an alias for the Boolean class. I use the alias when declaring a variable and the class name when calling a method on the class.

James Boother
Out of interest - why would you use both? I advocate using one or the other. Either use the aliases or don't, otherwise the code looks messy and inconsistent.
Kent Boogaart
I think it looks messy when you don't use both. Use the alias for declaring the datatype and use the actuall class name when accessing static methods:string x = String.Format("Today is: {0}", DateTime.Now);
Scott Dorman
So you'd do:int i = Int32.Parse(...);?I have a couple of problems with that. Firstly, VS will highlight differently by default (I know you can change this but most devs just use the default syntax highlighting). Secondly, searching is harder especially with longs (long / Int64).
Kent Boogaart
Yes, that is the exact way it should be done. int is not the class name, you should not be calling methods on it. On the other hand, it is the builtin type, and defining Int32 i; is too verbose and not natural.
AviD
mixing aliases and class names just adds nothing to code clarity. Pick one and stick with it, imho
Arne Claassen
+5  A: 

There is no difference - bool is simply an alias of System.Boolean.

http://msdn.microsoft.com/en-us/library/c8f5xwh7(VS.71).aspx

Burly
A: 

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.

elifeinchrist