更好地为int转换为一个布尔值的方法 [英] Better way to convert an int to a boolean
本文介绍了更好地为int转换为一个布尔值的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
输入 INT
值只包含了1或0。
我可以写一个如果别人
语句解决这个问题。
The input int
value only consist out of 1 or 0.
I can solve the problem by writing a if else
statement.
难道没有办法投的 INT
到布尔
?
感谢
推荐答案
我假设0表示假。这意味着真正的不为0,所以你可以这样写:
I assume 0 means false. That means true is not 0 so you can just write:
bool boolValue = intValue != 0;
这篇关于更好地为int转换为一个布尔值的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文