我想检查用户的输入是否是数字。如果是,我希望该功能继续运行,否则要提醒他并再次运行。检查用户输入是否是数字
Console.WriteLine(String.Concat("choose your action" ,Environment.NewLine ,
"1.Deposit", Environment.NewLine,
"2.Withdraw", Environment.NewLine,
"3.CheckAccount"));
string c = Console.ReadLine();
int value = Convert.ToInt32(c);
if (value==char.IsLetterOrDigit(value)) //<----- no good why?
{
switch (value)
{
case 1:
Deposit();
return;
case 2:
Withdraw();
return;
case 3:
CheckAccount();
return;
}
}
不需要使用'String.Concat'队友!这里有一个运算符,即字符串连接运算符'+',它在对'String.Concat'的调用中被优化。 – antonijn