首页 新闻 赞助 找找看

输入字符串的格式不正确

-1
[已解决问题] 解决于 2013-09-11 19:27

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();         }     } }

阿羊的阿咩的主页 阿羊的阿咩 | 菜鸟二级 | 园豆:202
提问于:2013-09-11 16:39
< >
分享
最佳答案
1

原因看dudu

把中间的Console.Read()去掉,程序就利索了。

奖励园豆:5
kafka No.14 | 初学一级 |园豆:122 | 2013-09-11 16:59
其他回答(2)
0

问题出在

int age = Convert.ToInt32(strAge);  

如果stringAge的值是空字符串就会出现这个错误。

dudu | 园豆:31075 (高人七级) | 2013-09-11 16:46
0

如果strAge无法转换为数字,也会报这个错,你最好先判断一下能否转换为数字

你好,再见 | 园豆:105 (初学一级) | 2013-09-11 18:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册