将类型'byte'转换为'bool' [英] convert type 'byte' to 'bool'
本文介绍了将类型'byte'转换为'bool'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用以下
代码打印出&& -operation的真值表,不幸的是我得到了编译器错误:
for(byte i1 = 0; i1< = 1; i1 ++)
{
for(byte i2 = 0; i2< = 1; i2 ++)
{
bool a =(bool)i1; //错误:将类型''byte''转换为''bool''
bool b =(bool)i2; //错误:将类型''byte''转换为''bool''
bool result = a&& b;
}
}
如何解决这个问题?
thnx >
Chris
解决方案
bool a = Convert.ToBoolean(i1);
Willy 。
" Chris" < CH ******** @ pandora.be>在留言中写道
news:tv *********************** @ phobos.telenet-ops.be ...
我尝试使用以下代码打印出&& -operation的真值表,不幸的是我遇到编译错误:
for(byte i1 = 0; i1< = 1; i1 ++)
{
for(byte i2 = 0; i2< = 1; i2 ++)
{
bool a =(bool)i1; //错误:将类型''byte''转换为''bool''
bool b =(bool)i2; //错误:将类型''byte''转换为''bool''
bool result = a&& b;
}
}
如何解决这个问题?
thnx
Chris
为什么不做bool result = i1&& i2"。
" Chris" < CH ******** @ pandora.be>在留言中写道
news:tv *********************** @ phobos.telenet-ops.be ...
我尝试使用以下代码打印出&& -operation的真值表,不幸的是我遇到编译错误:
for(byte i1 = 0; i1< = 1; i1 ++)
{
for(byte i2 = 0; i2< = 1; i2 ++)
{
bool a =(bool)i1; //错误:将类型''byte''转换为''bool''
bool b =(bool)i2; //错误:将类型''byte''转换为''bool''
bool result = a&& b;
}
}
如何解决这个问题?
thnx
Chris
使用Convert.ToBoolean而不是使用(bool)i1
Convert.ToBoolean(i1);
它会以这种方式工作。
问候,
Tarakeshwar
" Chris" < CH ******** @ pandora.be>在留言中写道
news:tv *********************** @ phobos.telenet-ops.be ...
我尝试使用以下代码打印出&& -operation的真值表,不幸的是我遇到编译错误:
for(byte i1 = 0; i1< = 1; i1 ++)
{
for(byte i2 = 0; i2< = 1; i2 ++)
{
bool a =(bool)i1; //错误:将类型''byte''转换为''bool''
bool b =(bool)i2; //错误:将类型''byte''转换为''bool''
bool result = a&& b;
}
}
如何解决这个问题?
thnx
Chris
Hi,
I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :
for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool a = (bool)i1; // ERROR : convert type ''byte'' to ''bool''
bool b = (bool)i2; // ERROR : convert type ''byte'' to ''bool''
bool result = a && b;
}
}
how do I solve this ?
thnx
Chris
解决方案
bool a = Convert.ToBoolean(i1);
Willy.
"Chris" <ch********@pandora.be> wrote in message
news:tv***********************@phobos.telenet-ops.be...Hi,
I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :
for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool a = (bool)i1; // ERROR : convert type ''byte'' to ''bool''
bool b = (bool)i2; // ERROR : convert type ''byte'' to ''bool''
bool result = a && b;
}
}
how do I solve this ?
thnx
Chris
Why not just do "bool result = i1 && i2".
"Chris" <ch********@pandora.be> wrote in message
news:tv***********************@phobos.telenet-ops.be...Hi,
I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :
for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool a = (bool)i1; // ERROR : convert type ''byte'' to ''bool''
bool b = (bool)i2; // ERROR : convert type ''byte'' to ''bool''
bool result = a && b;
}
}
how do I solve this ?
thnx
Chris
use Convert.ToBoolean instead of using (bool) i1
Convert.ToBoolean(i1);
It will work this way.
Regards,
Tarakeshwar
"Chris" <ch********@pandora.be> wrote in message
news:tv***********************@phobos.telenet-ops.be...Hi,
I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :
for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool a = (bool)i1; // ERROR : convert type ''byte'' to ''bool''
bool b = (bool)i2; // ERROR : convert type ''byte'' to ''bool''
bool result = a && b;
}
}
how do I solve this ?
thnx
Chris
这篇关于将类型'byte'转换为'bool'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文