正在加载图片...
类型转换 C#允许使用两种转换的方式:隐式转换和显式转 换 ■隐式转换 (imnlicit conversion) 不需要加以 static void Main() byte value1 23; 法因4上业 转换源 byte value2 10; sbyte short、int、lg long total value1 value2; byte short、ushort, cimal short int、1ong、fl( Console.WriteLine(total); ushort int、uint、lorJ int long、f1oat、double或decimal uint long、ulong、f1oat、double或decimal long float、double彧decimal ulong float、double或decimal char ushort、int、uint、long、ulong、float、double或decimal float double 19 19 类型转换 ▪ C#允许使用两种转换的方式:隐式转换和显式转 换 ▪ 隐式转换(implicit conversion) ◼ 不需要加以声明就可以进行的转换 ◼ 只允许发生在从小的值范围的类型到大的值范围的类 型的转换(无符号可以转换为符号) ◼ 从int、uint或long到float的转换以及从long、ulong 到double的转换的精度可能会降低,但不会引起数量 上的丢失 ◼ 不存在数值型到char型,以及浮点与decimal之间的隐 式转换
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有