I have a small C # console application that I am writing.
I want the application to wait for instructions from the user regarding pressing the Y or N key (if any other key is pressed, the application ignores this and expects either Y or N, and then runs a code depending on the Y or N Answers.
I came up with this idea,
while (true)
{
ConsoleKeyInfo result = Console.ReadKey();
if ((result.KeyChar == "Y") || (result.KeyChar == "y"))
{
Console.WriteLine("I'll now do stuff.");
break;
}
else if ((result.KeyChar == "N") || (result.KeyChar == "n"))
{
Console.WriteLine("I wont do anything");
break;
}
}
Sadly though, VS says he doesn't like the result. Keychat == since the operand can not apply to 'char' or 'string'
Any help please?
Thanks in advance.
source
share