Implicit numeric conversions table

Domains: C#

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

From To
sbyte shortintlongfloatdouble, or decimal
byte shortushortintuintlongulongfloatdouble, or decimal
short intlongfloatdouble, or decimal
ushort intuintlongulongfloatdouble, or decimal
int longfloatdouble, or decimal
uint longulongfloatdouble, or decimal
long floatdouble, or decimal
char ushortintuintlongulongfloatdouble, or decimal
float double
ulong floatdouble, 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 intuintlong, 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 sbytebyteshortushortuint, 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'
Page structure