Implicit Numeric Conversions Table (C# Reference)

 

Updated: July 20, 2015

The following table shows the predefined implicit numeric conversions. Implicit conversions might occur in many situations, including method invoking and assignment statements.

FromTo
sbyteshort, int, long, float, double, or decimal
byteshort, ushort, int, uint, long, ulong, float, double, or decimal
shortint, long, float, double, or decimal
ushortint, uint, long, ulong, float, double, or decimal
intlong, float, double, or decimal
uintlong, ulong, float, double, or decimal
longfloat, double, or decimal
charushort, int, uint, long, ulong, float, double, or decimal
floatdouble
ulongfloat, double, or decimal
  • 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 floating-point types and the decimal type.

  • A constant expression of type int can be converted to sbyte, byte, short, ushort, uint, or ulong, provided the value of the constant expression is within the range of the destination type.

For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.

C# Reference
C# Programming Guide
Integral Types Table
Built-In Types Table
Explicit Numeric Conversions Table
Casting and Type Conversions

Show: