2
我看不到为什么第5行编译失败,而第4行没有问题。常量值不能转换为int
static void Main(string[] args)
{
byte b = 0;
int i = (int)(0xffffff00 | b); // ok
int j = (int)(0xffffff00 | (byte)0); // error: Constant value cannot be converted to a 'int' (use 'unchecked' syntax to override)
}
可能重复[C# - 恒定值“4294901760”不能转换为“廉政”( http://stackoverflow.com/questions/6027572/c-sharp-constant-value-4294901760-cannot-be-converted-to-a-int) – 2015-03-13 17:26:52
@ColinCochrane它是相关的,但不是一个重复。这就解释了为什么这个值不能转换为int类型,但是这个问题是关于为什么这个错误只发生在一个常量上,而不是一个被设置为相同值的变量。 – juharr 2015-03-13 17:29:23