Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# can't cast bool to int

Tags:

c#

.net

We all know that in C# we can't cast bool to int. I wanted to see what is the binary representation of true with bitmask, but I can't use (bool & int).. I think the problem is the architecture desicion "true is true, not any number != 0" (C++) and I was wondering what the benefits of such an architecture are? What is so bad with the C true/false concept?

like image 850
Svetlozar Angelov Avatar asked Jun 03 '09 19:06

Svetlozar Angelov


1 Answers

It's clearer to the programmer when an integer can't be used for true or false.

if (5 > 0) is easier to understand rather than if(5)

It's the same reason why they don't allow fall through conditions in switch statements. It's too easy to make a mistake.

like image 139
kemiller2002 Avatar answered Oct 01 '22 13:10

kemiller2002