I'm facing the problem that C# in my case can't cast the number 1 to bool. In my scenario (bool)intValue
doesn't work. I get an InvalidCastException
. I know I can use Convert.ToBoolean(...)
but I'm just wondering it doesn't work. Any explanation for this?
My code is
if (actualValueType.Name == "Boolean" || setValueType.Name == "Boolean")
{
if ((bool)actualValue != (bool)setValue)
...
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…