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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version