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

- 70,104
- 56
- 326
- 368

- 50,926
- 41
- 133
- 199
15 Answers
bool
is an alias for System.Boolean
just as int
is an alias for System.Int32
. See a full list of aliases here: Built-In Types Table (C# Reference).

- 2,291
- 4
- 28
- 42

- 175,602
- 35
- 392
- 393
-
5From 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 Mar 18 '10 at 11:39
-
7@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 Mar 18 '10 at 13:47
-
9@asmin: It's a C thing. int, float etc are familiar keywords to C and C++ programmers, so Microsoft decided to use these aliases for consistency. – Mike Chamberlain Feb 03 '11 at 01:34
-
46@Mikey I'm pretty sure that Java decided to use these aliases for consistency, and Microsoft decided to use Java for consistency... :-) – max Aug 19 '11 at 14:07
-
20@MaxWell In Java, `boolean` and `Boolean` is not the same thing. One is a primitive data type and the other is an object. – Rosdi Kasim Mar 28 '13 at 04:42
-
2yeah I know, I was just making a funny. – max Apr 05 '13 at 21:36
-
2This alias just caused me a problem. I use bool because I thought it was the "correct" type, then I got confused why my "bool" MVC DisplayTemplate wasn't firing. Turns out I need to name it Boolean. If I realized Boolean was the official type and bool was just an alias for convenience, I'd have used Boolean from the outset. – Michael12345 Jan 30 '14 at 23:43
-
What is the difference between `Bool` and `bool`? – Legends Jun 17 '20 at 19:19
-
Thumbs down because this didn't answer the question on what is the difference. – Lightsout Feb 27 '21 at 03:42
I don't believe there is one.
bool
is just an alias for System.Boolean

- 5,669
- 5
- 21
- 34

- 1,359
- 1
- 9
- 14
There is no difference - bool is simply an alias of System.Boolean.
http://msdn.microsoft.com/en-us/library/c8f5xwh7(VS.71).aspx

- 13,476
- 14
- 56
- 65
I realise this is many years later but I stumbled across this page from google with the same question.
There is one minor difference on the MSDN page as of now.
VS2005
Note:
If you require a Boolean variable that can also have a value of null, use bool. For more information, see Nullable Types (C# Programming Guide).
VS2010
Note:
If you require a Boolean variable that can also have a value of null, use bool?. For more information, see Nullable Types (C# Programming Guide).

- 1,131
- 15
- 30
-
3I was tripped up by this - it seems to be a bug in the documentation. I saw the VS2005 page first (it appears higher in Google rankings for me!), and thought it implied that `bool` could contain null, but `Boolean` couldn't. Even though there is a link from the older to the newer documentation, I didn't read the newer documentation thoroughly enough to notice the single `?` difference. – Logan Pickup Oct 27 '15 at 20:16
-
@Timothy Macharia Who/what is wrong? What does "convert to null" mean? – The incredible Jan Dec 16 '20 at 08:28
They are the same.
C# programmers tend to prefer bool
. It's less typing and just feels more natural from someone coming from that language family. It also guarantees you get the actual System.Boolean
type (where otherwise it's possible to make your own Boolean
type in a different namespace and the type resolution could become ambiguous).
But if you're 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 and helps simplify conversion back and forth between C# and VB.Net.

- 399,467
- 113
- 570
- 794
As has been said, they are the same. There are two because bool is a C# keyword and Boolean a .Net class.

- 17,808
- 7
- 62
- 75
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.

- 41,623
- 1
- 17
- 5
-
11Out 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 Sep 25 '08 at 17:42
-
3I 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 Sep 25 '08 at 17:49
-
2So 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 Sep 25 '08 at 18:20
-
5Yes, 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 Sep 25 '08 at 19:14
-
7mixing aliases and class names just adds nothing to code clarity. Pick one and stick with it, imho – Arne Claassen Sep 09 '09 at 22:07
-
1I agreed with Kent Boogaart's comment. Yes, int i = Int32.Parse is weird. But for java user, Using bool and boolean the alias when declaring Boolean class is not bad idea. – Choi May 29 '19 at 07:55
They are the same, Bool is just System.Boolean shortened. Use Boolean when you are with a VB.net programmer, since it works with both C# and Vb

- 3,755
- 3
- 19
- 42
Note that Boolean
will only work were you have using System;
(which is usually, but not necessarily, included) (unless you write it out as System.Boolean
). bool
does not need using System;

- 101,701
- 37
- 181
- 258
bool is a primitive type, meaning that the value (true/false in this case) is stored directly in the variable. Boolean is an object. A variable of type Boolean stores a reference to a Boolean object. The only real difference is storage. An object will always take up more memory than a primitive type, but in reality, changing all your Boolean values to bool isn't going to have any noticeable impact on memory usage.
I was wrong; that's how it works in java with boolean and Boolean. In C#, bool and Boolean are both reference types. Both of them store their value directly in the variable, both of them cannot be null, and both of them require a "convertTO" method to store their values in another type (such as int). It only matters which one you use if you need to call a static function defined within the Boolean class.

- 45
- 2
-
`bool` and `Boolean` are not two different types, that one type is not a reference type, you can call a static method on that *one* type using either identifier, and you don't in fact need to call a `ConvertTo` method to convert it to another type. – Servy Aug 05 '16 at 17:59
-
4It's not correct that "`bool` and `Boolean` are both reference types". The words `bool` and `Boolean` both refer to the same type, and that type is a value type, not a reference type. – Tanner Swett Jan 29 '17 at 18:04
-
Thanks, I was trying to check if C# acted the same as java in this field. You answer is the only one that compares it to java (even though maybe not intentionally). :) – bvdb Feb 08 '17 at 14:38
No actual difference unless you get the type string. There when you use reflection or GetType() you get {Name = "Boolean" FullName = "System.Boolean"} for both.

- 571
- 3
- 8
bool is an alias for Boolean. What aliases do is replace one string of text with another (like search/replace-all in notepad++), just before the code is compiled. Using one over the other has no effect at run-time.
In most other languages, one would be a primitive type and the other would be an object type (value type and reference type in C# jargon). C# does not give you the option of choosing between the two. When you want to call a static method defined in the Boolean class, it auto-magically treats Boolean as a reference type. If you create a new Boolean variable, it auto-magically treats it as a reference type (unless you use the Activator.CreateInstance method).

- 72
- 9
Perhaps bool is a tad "lighter" than Boolean; Interestingly, changing this:
namespace DuckbillServerWebAPI.Models
{
public class Expense
{
. . .
public bool CanUseOnItems { get; set; }
}
}
...to this:
namespace DuckbillServerWebAPI.Models
{
public class Expense
{
. . .
public Boolean CanUseOnItems { get; set; }
}
}
...caused my cs file to sprout a "using System;" Changing the type back to "bool" caused the using clause's hair to turn grey.
(Visual Studio 2010, WebAPI project)

- 8,547
- 144
- 472
- 862
-
It's `System.Boolean` rather than just `Boolean`. The `using System;` was showing up because it allowed `Boolean` to be properly interpreted as `System.Boolean`. Not really lighter so much as just less verbose. – Nat May 14 '20 at 09:31