Implicit numeric conversions table (C# Reference)

The following table shows the predefined implicit conversions between .NET numeric types.

From To
sbyte short, int, long, float, double, or decimal
byte short, ushort, int, uint, long, ulong, float, double, or decimal
short int, long, float, double, or decimal
ushort int, uint, long, ulong, float, double, or decimal
int long, float, double, or decimal
uint long, ulong, float, double, or decimal
long float, double, or decimal
char ushort, int, uint, long, ulong, float, double, or decimal
float double
ulong float, double, or decimal

Remarks

  • Any integral type is implicitly convertible to any floating-point type.

  • Precision but not magnitude might be lost in the conversions from int, uint, long, or ulong to float and from long or ulong to double.

  • There are no implicit conversions to the char type.

  • There are no implicit conversions between the float and double types and the decimal type.

  • A value of a constant expression of type int (for example, a value represented by an integral literal) can be converted to sbyte, byte, short, ushort, uint, or ulong, provided it's within the range of the destination type:

    byte a = 13;    // Compiles
    byte b = 300;   // CS0031: Constant value '300' cannot be converted to a 'byte'
    

For more information about implicit conversions, see the Implicit conversions section of the C# language specification.

See also