在下面的:
public class p
{
short? mID;
short? dID;
}
short id = p.mID ?? -p.dID.Value;
Run Code Online (Sandbox Code Playgroud)
编译器给我错误:
错误21无法将类型'int'隐式转换为'short'.存在显式转换(您是否错过了演员?)
我必须将代码更改为以下代码才能工作:
short id = p.mID ?? (short)-p.dID.Value;
Run Code Online (Sandbox Code Playgroud)
好像编译器正在执行类似(int)0 - p.dID.Value,或Int16.operator - 正在返回Int32s ......?