【发布时间】:2022-01-11 20:11:17
【问题描述】:
我试图要求用户仅按“+”键,如果用户输入错误,请告诉他这不是操作;例如,如果用户输入数字或任何其他键,告诉用户“你必须输入一个操作” 我已经尝试了下面的代码,但没有得到修复!
Console.WriteLine("press '+' to add\npress '-' to delete");
//these are the ways i have tried:
//1:
char add = '+';
if (Console.ReadKey() == add) ;
//2:
string input = Console.ReadLine();
char inputChar = Convert.ToChar(input);
//if user give number the program shows error to me
if (inputChar == add) ;
//3:
if (Console.ReadKey().Key == ConsoleKey.+) ;
【问题讨论】:
标签: c# character calculator