我有以下代码:
使用系统;
namespace MyApp {
class KeyBoardInputTest {
static void Main() {
Console.Write("Enter a character >\t");
char ch = (char)Console.Read();
Console.WriteLine("");
if(Char.IsLetter(ch)) {
if(Char.IsUpper(ch))
Console.WriteLine("You have entered an upper case character");
else
Console.WriteLine("You have entered a lower case character");
}
else if(Char.IsNumber(ch))
Console.WriteLine("You have entered a numeric character");
else
Console.WriteLine("You have entered a non alpha-numeric character");
Console.Read();
}
}
}
输入后a直接显示结果,无需等待我按下Enter
使用Console.ReadLine()
给出错误 -
error CS0030: Cannot convert type 'string' to 'char'
使用Console.ReadKey()
给出错误 -
error CS0030: Cannot convert type 'System.ConsoleKeyInfo' to 'char'