編譯器錯誤 CS0031

無法將常數值 'value' 轉換為 'type'

嘗試將值指派給其類型無法儲存值的變數。 如需詳細資訊,請參閱類型

下列範例會在已核對及未核對的內容中產生 CS0031:

// CS0031.cs
namespace CS0031
{
    public class Program
    {
        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;
            }
        }
    }
}

另請參閱