Tuesday, March 06, 2007

ReadKey() in Console apps

Color me if you doubt this! But i came across this while i was working on Console application!
2 cents - If you want to break your console app before in .net or VB you used to specify:
Console.Read //or sometimes Console.Readline;

It meant that you can press any key to continue but it is actually "Enter" key that need to be pressed to exit out of the app! :)

However, there was a workaround to take in any key other than Enter key but you had to go through the API core to get stuff working. Now, in .net 2.0 Microsoft recoginized this and has attempted to come up with elegant solution by providing ReadKey() method.

Console.ReadKey(); accepts any key :) More below -
http://msdn2.microsoft.com/en-us/library/system.console.readkey(vs.80).aspx

Cheers - Dipesh

No comments: