📜  隐式与显式转换 c# 代码示例

📅  最后修改于: 2022-03-11 14:49:11.745000             🧑  作者: Mango

代码示例1
// Implicit (converting from a smaller type to a larger type)
int anInt = 12;
float aFloat = anInt;

Console.WriteLine($"anInt: {anInt}"); // anInt: 12
Console.WriteLine($"aFloat: {aFloat}"); // aFloat: 12

// Explicit (converting from a larger type to a smaller type)
float aFloat = 12.945f;
int anInt = (int) aFloat;

Console.WriteLine($"aFloat: {aFloat}"); // aFloat: 12.945
Console.WriteLine($"anInt: {anInt}"); // anInt: 12