I have a small C # console application that reads a key and checks if the key was a question mark:
ConsoleKeyInfo ki = System.Console.ReadKey(); if (ki.ConsoleKey.Oem2)
I came to Oem2 when I saw what value was really assigned in the debugger, because there is no console code for the question mark > .
Now I could use ki.KeyChar instead, but the application should also respond to certain keys (e.g. media keys) that do not map to characters. To determine which key was actually pressed, implicitly check both ConsoleKey and KeyChar . On the other hand, don't rely on Oem2 to always display on ? in all circumstances and regions.
Is it better to check both properties to determine which key was pressed?
Any insight into why ConsoleKeyInfo was designed this way is appreciated.
Eric J.
source share