| title | Implicit Numeric Conversions Table (C# Reference) | ||||
|---|---|---|---|---|---|
| ms.date | 07/20/2015 | ||||
| ms.prod | .net | ||||
| ms.technology |
|
||||
| ms.topic | article | ||||
| helpviewer_keywords |
|
||||
| ms.assetid | 72eb5a94-0491-48bf-8032-d7ebfdfeb8d8 | ||||
| caps.latest.revision | 12 | ||||
| author | BillWagner | ||||
| ms.author | wiwagn |
The following table shows the predefined implicit numeric conversions. Implicit conversions might occur in many situations, including method invoking and assignment statements.
| 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 |
-
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 floating-point types and the
decimaltype. -
A constant expression of type
intcan be converted tosbyte,byte,short,ushort,uint, orulong, provided the value of the constant expression is within the range of the destination type.
[!INCLUDECSharplangspec]
C# Reference
C# Programming Guide
Integral Types Table
Built-In Types Table
Explicit Numeric Conversions Table
Casting and Type Conversions