存在从 int 到 long、float、double 或 decimal 的预定义隐式转换。例如:
// '123' is an int, so an implicit conversion takes place here:
float f = 123;
存在从 sbyte、byte、short、ushort 或 char 到 int 的预定义隐式转换。例如,如果不进行强制转换,下面的赋值语句将产生编译错误:
long aLong = 22;
int i1 = aLong; // Error: no implicit conversion from long.
int i2 = (int)aLong; // OK: explicit conversion.
还请注意,不存在从浮点型到 int 类型的隐式转换。例如,除非使用显式强制转换,否则以下语句将生成一个编译器错误:
int x = 3.0; // Error: no implicit conversion from double.
int y = (int)3.0; // OK: explicit conversion. 有关兼用浮点型和整型的算术表达式的更多信息,请参见 float 和 double。