C# Developers' Journal (original) (raw)

getch() in C# Is there anything wrong with the following to emulate getch() (aside from not handling exceptions) using .NET 2.0?

using System;

public class Input { static void Main(string[] args) { char ch = getch(); Console.WriteLine("You entered: {0}", ch); }

static char getch()
{
    ConsoleKeyInfo cki = Console.ReadKey(true);
    return cki.KeyChar;
}

}