问题描述
我们都知道,在C#中,我们不能施放布尔为int。我想看看什么是真正的与位掩码的二进制重新presentation,但我不能使用(布尔&安培; INT)!我认为这个问题是建筑desicion真实不虚,没有任何数量= 0(C ++),我想知道这种架构的好处是什么?有什么用C真/假的概念是如此糟糕?
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?
推荐答案
这是更清楚当一个整数,不能用于编程真
或假
。
It's clearer to the programmer when an integer can't be used for true
or false
.
如果(5 0)
更容易理解,而不是如果(5)
if (5 > 0)
is easier to understand rather than if(5)
这是同样的原因,他们不允许通过秋季在switch语句中的条件。这太容易犯错误。
It's the same reason why they don't allow fall through conditions in switch statements. It's too easy to make a mistake.
这篇关于C#中无法施展BOOL为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!