Errore del compilatore CS0031

Non è possibile convertire il valore costante 'value' in 'type'.

Si è provato ad assegnare un valore a una variabile il cui tipo non può archiviare il valore. Per altre informazioni, vedere Tipi.

L'esempio seguente genera l'errore CS0031 nei contesti selezionati e deselezionati:

// 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;
            }
        }
    }
}

Vedi anche