我想做一个比较:
ComboBox.SelectedItem 对象类型为string.Empty 结合"||"
如果我用上面的命令运行我会得到一个错误:
"Operator '||' cannot be applied to operands of type 'object' and 'bool' "
代码
if (comboBox2.SelectedItem || comboBox1.SelectedItem == string.Empty )
最佳答案
试试这个:
if ((comboBox1.SelectedItem?.Equals(string.Empty) ?? false)
|| (comboBox2.SelectedItem?.Equals(string.Empty) ?? false))
关于c# - 运算符 '||' 不能应用于类型 'object' 和 'bool' 的操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52552015/