c# - 条件表达式的类型无法确定为

标签 c# mono monodevelop

当我在 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/

相关文章:

c# - Xamarin 安装问题

c# - xUnit + VS2015,按特征分组有效吗?

c# - WPF按钮单击事件不起作用

c# - 在基元列表上使用 DataContractSerializer 的自定义元素名称

c# - 在 Xamarin.Forms 中使用 android 支持库 API 级别 26 (MonoAndroid 8.0 Oreo)?

ios - 从 VS 调试 iOS 时,程序 'Mono' 已退出,代码为 0 (0x0)

user-interface - 在 MonoDevelop 中打开 GUI 设计器

c# - 从未从 Web API 2 调用的 HTML5 EventSource onmessage

macos - 如何在 OSX 上将 T4 模板与 MonoDevelop 2.2 一起使用

monodevelop - “GenerateDepsFile”任务意外失败