苏飞论坛
标题:
C#怎么将布尔Boolean类型转成整型Int类型
[打印本页]
作者:
站长苏飞
时间:
2013-6-28 15:03
标题:
C#怎么将布尔Boolean类型转成整型Int类型
这具其实方法很简单
大家看下面代码
[code=csharp] Boolean b = false; ;
int a = Convert.ToInt32(b);
b = true; ;
int c = Convert.ToInt32(b);[/code]
a=0
c=1
也就是说true=1
false=0
[groupid=74]sufeinet总群[/groupid]
作者:
风雅。
时间:
2013-7-1 09:14
反过来就是不用0的皆为true。
当我打出来这句话的时候心中突然一惊,那么负数呢。说实话这个我还真没试过。
于是做一个尝试[code=csharp]int i = -1;
bool bl = Convert.ToBoolean(i);
if (bl)
{
MessageBox.Show("True!");
}[/code]
然后做一调试,负数的情况 也为True。
即非0皆为True..
欢迎光临 苏飞论坛 (http://www.sufeinet.com/)
Powered by Discuz! X3.4