1. 程式人生 > >使用TryParse()來執行數值轉換

使用TryParse()來執行數值轉換

數值轉換 分享圖片 oid highlight alt tel image 技術分享 AS

技術分享圖片

        static void Main()
        {
            var ageText = "25";
            if (int.TryParse(ageText,out int age))
            {
                Console.WriteLine("Hi,My age is {0}",age);
            }
            else
            {
                Console.WriteLine("age {0} is not valid",ageText);
            }
            Console.ReadKey();
        }

  

使用TryParse()來執行數值轉換