3

Possible Duplicate:
What is the difference between Bool and Boolean types in C#

Why does C# use the word bool intead of boolean for boolean types?

(I just wasted 5 mins trying to work out why my code wasn't compiling!)

Community
  • 1
  • 1
Craig Johnston
  • 7,467
  • 16
  • 40
  • 47

8 Answers8

24

Presumably because that's the keyword C++ uses for its boolean type, and C# retains much of the syntax to help programmers comfortable with that language migrate more easily. Old habits die hard.

It's also shorter, which saves typing. Programmers are a notoriously lazy bunch, and for good reason.

But remember that bool is only an alias in C# for the System.Boolean type. You can certainly use Boolean instead if you prefer (but of course, you'll have to capitalize it, since C# is case-sensitive).

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
9

Same reason it uses int for integer. programmers are lazy. :)

jb.
  • 9,921
  • 12
  • 54
  • 90
1

It is just the decision the language designer made, probably because it is shorter. It is also the keyword many languages use.

user623879
  • 4,066
  • 9
  • 38
  • 53
1

Perhaps the same reason they chose int instead Integer or Int32 - a similarity with C++!

VinayC
  • 47,395
  • 5
  • 59
  • 72
1

Probably because if historical reasons. bool and BOOL types were often used in C and C++ libraries that preceded C#.

kgiannakakis
  • 103,016
  • 27
  • 158
  • 194
1

Because the inventor of the Boolean logic was named Bool*e* (thanks Cody). So you got Bools and boolean operators to operate on them. Makes sense, not?

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
0

bool is simply an alias of System.Boolean - meant to save you 3 characters per declaration :)

Doron Zavelevsky
  • 1,202
  • 1
  • 10
  • 19
0

Pretty much all C style languages use "bool", it's not something that's peculiar to C# by any means...

MattDavey
  • 8,897
  • 3
  • 31
  • 54