猿问

输入字符串的格式不正确

using System; using System.Collections.Generic; using System.Linq; using System.Text;

namespace Week02_Console {     class Program     {         static void Main(string[] args)         {             Console.WriteLine("This's the first lab");

            Console.WriteLine("What's your name?");             string name = Console.ReadLine();             Console.WriteLine("Merry X’mas! {0}!", name);             Console.Read();

            Console.WriteLine("This's the second lab");

            Console.WriteLine("Enter your age please :");             string strAge = Console.ReadLine();

            int age = Convert.ToInt32(strAge);             Console.WriteLine("You'll be {0}next year!", age + 1);             Console.Read();         }     } }


慕的地10843
浏览 689回答 2
2回答

犯罪嫌疑人X

问题出在int age = Convert.ToInt32(strAge);如果stringAge的值是空字符串就会出现这个错误。
随时随地看视频慕课网APP
我要回答