KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a small C# console app I am writing. I would like the app to wait for instruction from the user regarding either a Y or a N keypress (if any other key is pressed the app ignores this and waits for either a Y or a N and then runs code dependent on the Y or N answer. 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 its doesnt like the result.Keychat == as the operand cant be applied to a 'char' or 'string' Any help please? Thanks in advance.
Tags (comma-separated)
Save Edits
Cancel