Implicit numeric conversions table
Domains:
C#
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, orulongtofloatand fromlongorulongtodouble. -
There are no implicit conversions to the
chartype. -
There are no implicit conversions between the
floatanddoubletypes and thedecimaltype. -
A value of a constant expression of type
int(for example, a value represented by an integral literal) can be converted tosbyte,byte,short,ushort,uint, orulong, 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
Semantic portal