What is an implicit conversion
Implicit Conversion
Implicit conversion is to use it directly, for example, you can use a byte type directly on int.
For example, the following directly assigns b of byte to n of int, and uses it directly. There are no additional keywords, and the system automatically completes the type conversion.
byte b = 1;
int n = b;
Implicit numerical conversion table (excerpted from MSDN)
Notes (excerpted from MSDN)
The accuracy of the conversion from int, uint, or long to float and from long to double may be reduced, but the numerical size is not affected.
There is no implicit conversion to char type.
There is no implicit conversion between floating point type and decimal type.
A constant expression of type int can be converted to sbyte, byte, short, ushort, uint, or ulong, provided that the value of the constant expression is within the range of the target type.
Implicit Conversion
Implicit conversion is to use it directly, for example, you can use a byte type directly on int.
For example, the following directly assigns b of byte to n of int, and uses it directly. There are no additional keywords, and the system automatically completes the type conversion.
Copy the codeThe code is as follows:
byte b = 1;
int n = b;
Implicit numerical conversion table (excerpted from MSDN)
from |
arrive |
---|---|
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 |
Notes (excerpted from MSDN)
The accuracy of the conversion from int, uint, or long to float and from long to double may be reduced, but the numerical size is not affected.
There is no implicit conversion to char type.
There is no implicit conversion between floating point type and decimal type.
A constant expression of type int can be converted to sbyte, byte, short, ushort, uint, or ulong, provided that the value of the constant expression is within the range of the target type.