日期:2014-05-18  浏览次数:21274 次

无法将类型“bool”隐式转换为“string"
[code=C#][/code]
string classID = Nbp(parameter, "IsRed");
  string Parentid = "";  
  if (classID = false)
  {
  Parentid = "";
  }
  else
  {
  Parentid = "IsRed=" + classID + "and"; 
  }
“IsRed”是bool类型,我想判断 classId为false时parentid="";
if(classId=false)这个地方该怎么去判断?

------解决方案--------------------
不如这样写
Parentid = classId != "false" ? ("IsRed=" + classID + "and") : "";
------解决方案--------------------
Nbp(parameter, "IsRed")

你这个事干啥的?
返回的是什么类型?

把相关代码贴出来

------解决方案--------------------
Convert.ToBoolean(classId)
or
(bool)classId
------解决方案--------------------
if (classID = false)
首先判断是否相等用的是 双等号 == ,单等号是赋值,其次 string 类型不能和 bool 类型直接比较,至少有一方要转换,基于你上面的代码,
if (classID == "false")
这样判断省事些,或者1楼三元运算
------解决方案--------------------
探讨

if (classID = false)
首先判断是否相等用的是 双等号 == ,单等号是赋值,其次 string 类型不能和 bool 类型直接比较,至少有一方要转换,基于你上面的代码,
if (classID == "false")
这样判断省事些,或者1楼三元运算

------解决方案--------------------
Nbp(parameter, "IsRed")
这个方法返回的值是什么?

------解决方案--------------------
探讨

如果用“0”和“1”代替该怎么写?

------解决方案--------------------
Nbp方法直接返回int型变量就行了!
0:false 1:true

int classID = Nbp(parameter, "IsRed");
string Parentid = "";
if (classID == 0)
{
Parentid = "false";
}
else
{
Parentid = "true";
}
Parentid = "IsRed=" + Parentid + "and";