C# ConsoleKeyInfo KeyChar
Description
ConsoleKeyInfo KeyChar
gets the Unicode character represented
by the current ConsoleKeyInfo object.
Syntax
ConsoleKeyInfo.KeyChar
has the following syntax.
public char KeyChar { get; }
Example
The following example uses the KeyChar property to add the characters input by the user into a string. The example ignores special keys other than ENTER, ESC, and BACKSPACE.
using System;//from www . j av a 2s. c o m
public class Example
{
public static void Main()
{
ConsoleKeyInfo keyInfo;
Console.WriteLine("Enter a string. Press <Enter> or Esc to exit.");
keyInfo = Console.ReadKey(true);
Console.Write(keyInfo.KeyChar);
}
}
The code above generates the following result.