C#的类型转换
using System;namespace demo_01{ class Program { static void Main(string[] args) { int a = 1; double b = 1.3; //使用转换工具类转换也会一定的精度 int c = Convert.ToInt32(b); //强制类型转换会损失精度 int d = (int)b; //常规类型转换 double e = (double)a; Console.WriteLine(c); Console.WriteLine(d); Console.WriteLine(e); //阻塞一下cmd消失 查看结果 Console.Read(); } }}
查看结果