更新:2007 年 11 月
错误消息
常数值“value”无法转换为“type”。(使用“unchecked”语法重写)
试图对类型不能存储值的变量赋值。有关更多信息,请参见类型(C# 编程指南)。
下面的示例在已检查和未检查的上下文中都会生成 CS0031:
// CS0031.cs
namespace CS0031
{
public class a
{
public static void Main()
{
int num = (int)2147483648M; //CS0031
// Try using a larger numeric type instead:
// long num = (long)2147483648M; //CS0031
const decimal d = -10M; // Decimal literal
unchecked
{
const byte b = (byte)d; // CS0031
// For small values try using a signed byte instead:
// const sbyte b = (sbyte)d;
}
}
}
}