Data type | Widens to data types1 |
---|---|
sbyte | sbyte, short, int, long, decimal, float, double |
byte | byte, short, ushort, int, uint, long, ulong, decimal, float, double |
short | short, int, long, decimal, float, double |
ushort | ushort, int, uint, long, ulong, decimal, float, double |
int | int, long, decimal, float, double2 |
uint | uint, long, ulong, decimal, float, double2 |
long | long, decimal, float, double2 |
ulong | ulong, decimal, float, double2 |
decimal | decimal, float, double2 |
float | float, double |
double | double |
Any enum | Its underlying integer type and any type to which it widens |
char | char, string |
char array | char array, string |
Any type | object |
Any derived type | Any base type from which it is derived3 |
Any type | Any interface it implements |
null | Any data or object type |
1 By definition, every data type widens to itself.
2 Conversions from int, uint, long, ulong, or decimal to float or double might result in loss of precision, but never in loss of magnitude. In this sense they do not incur information loss.
3 A type contains all the members of the base type, so it qualifies as an instance of the base type. In the opposite direction, the base type does not contain any new members defined by the derived type.
Widening conversions always succeed at run time and never incur data loss. They are always performed implicitly, even if no cast is used.