写个例子,谢
Console.WriteLine("请输入数字:");
string input = Console.ReadLine();
try
{
int i = int.Parse(input);
Console.WriteLine("输入的数字为:" + i.ToString());
}
catch
{
Console.WriteLine("输入字符为非数字");
}
Console.ReadKey();
在一楼的基础上加上try...catch,锦上添花
string input = Console.ReadLine();
try
{
int i = int.Parse(input);
Console.WriteLine("输入的数字为:" + i.ToString());
}
catch
{
Console.WriteLine("输入字符为非数字");
}
Console.ReadKey();
在一楼的基础上加上try...catch,锦上添花
温馨提示:答案为网友推荐,仅供参考
第1个回答 2012-05-04
Console.WriteLine("请输入数字!");
string s = Console.ReadLine();
int i = int.Parse(s);
Console.WriteLine(s.ToString());
Console.ReadKey();
string s = Console.ReadLine();
int i = int.Parse(s);
Console.WriteLine(s.ToString());
Console.ReadKey();