当我在 MonoDevelop 中编译我的 C# 项目时,出现以下错误:
无法确定条件表达式的类型,因为 'byte' 和 'int' 相互隐式转换
代码片段:
byte oldType = type;
type = bindings[type];
//Ignores updating blocks that are the same and send block only to the player
if (b == (byte)((painting || action == 1) ? type : 0))
{
if (painting || oldType != type) { SendBlockchange(x, y, z, b); } return;
}
这是错误中突出显示的行:
if (b == (byte)((painting || action == 1) ? type : 0))
非常感谢您的帮助!
最佳答案
条件运算符是一个表达式,因此需要一个返回类型,并且两个路径必须具有相同的返回类型。
(painting || action == 1) ? type : (byte)0
关于c# - 条件表达式的类型无法确定为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5524968/