C#小白学习笔记(5)数据类型转换

namespace Demo05_reverse
{
    class Program
    {
        static void Main(string[] args)
        {
            float f = 55.5f; //只要是小数就默认为double类型,数字后加f为显式转换,将double转换为float
            double d = 66.6; 
            decimal m = 77.7m;//默认右侧为double类型,数字后加m为显式转换,将double转换为decimal,涉及到财务用decimal
            int i;
            i = Convert.ToInt32(d);//int类型取值范围比较小
            Console.WriteLine(i);

            string str = "18";
            int age = int.Parse(str);
            Console.WriteLine(age);
            Console.ReadKey();
        }
    }
}

运行结果如下:

posted @ 2020-09-16 11:39  ___lucky  阅读(208)  评论(0)    收藏  举报