.Net之旅-C#·把字符串数据类型转换为整型,或者其他类型



            #region 把字符串转换为整数,或者双精度浮点类型 522
            int age;

            string s = "20";
            // 字符串转换为整型  变成32为的整型
            age = Convert.ToInt32(s);
            Console.WriteLine("字符串转换为32位整型:"+age);

            float weight;
            double height;
            s = "80.5";
            weight = Convert.ToSingle(s);
            Console.WriteLine("字符串转换为单精度浮点类型:"+weight);

            //变成双精度数字类型
            s = "1.78";
            height = Convert.ToDouble(s);
            Console.WriteLine("字符串转换为双精度浮点类型"+height);

            #endregion

效果

 

猜你喜欢

转载自blog.csdn.net/chenggong9527/article/details/124909340