Convert.ToString(icdoCalcWiz.ihstOldValues[enmCalcWiz.position_value.ToString()])!=icdoCalcWiz.position_value
此处LHS的值将变为“”(空)
但在RHS中,该值将为NULL
我必须满足条件,例如Empty或Null是否相等
但按照上述条件,两者都不是:
答案 0 :(得分:4)
使用它。
if (string.IsNullOrEmpty("any string"))
{
}
还有一个String.IsNullOrWhitespace()方法,它指示指定的字符串是空,空还是仅由空格字符组成。
if(String.IsNullOrWhitespace(val))
{
return true;
}
以上是以下代码的快捷方式:
if(String.IsNullOrEmpty(val) || val.Trim().Length == 0)
{
return true;
}
答案 1 :(得分:1)
你可以尝试这个......
static string NullToString( object Value )
{
// Value.ToString() allows for Value being DBNull, but will also convert int, double, etc.
return Value == null ? "" : Value.ToString();
// If this is not what you want then this form may suit you better, handles 'Null' and DBNull otherwise tries a straight cast
// which will throw if Value isn't actually a string object.
//return Value == null || Value == DBNull.Value ? "" : (string)Value;
}
你的代码将写成......
Convert.ToString(icdoCalcWiz.ihstOldValues[enmCalcWiz.position_value.ToString()])!=
NullToString(icdoCalcWiz.position_value)
答案 2 :(得分:0)
答案 3 :(得分:0)
怎么样?
string lhs = Convert.ToString(icdoCalcWiz.ihstOldValues[enmCalcWiz.position_value.ToString()]);
string rhs = icdoCalcWiz.position_value;
if ( (lhs == null || lhs == string.Empty) && (rhs == null || rhs == string.Empty)){
return true;
} else {
return lhs == rhs;
}