【发布时间】:2011-01-04 17:12:16
【问题描述】:
如下:
public class p
{
short? mID;
short? dID;
}
short id = p.mID ?? -p.dID.Value;
编译器给了我错误:
错误 21 无法将类型“int”隐式转换为“short”。存在显式转换(您是否缺少演员表?)
我必须将代码更改为以下代码才能正常工作:
short id = p.mID ?? (short)-p.dID.Value;
就好像编译器正在执行 (int)0 - p.dID.Value 之类的操作,或者 Int16.operator - 正在返回 Int32s...?
【问题讨论】: