The System.Char data type is used to hold a single, Unicode character. It can be any small letter (a, b, c, …), any capital letter (A, B, C, …), any single digit (0, 1, 2,…) and special character (!, @, $, +, —, …) etc., all are treated as characters. To assign a character, you simply need to put them inside single quotes(''). For example: char ch = 'a';
Example 1: Input character and display it.
static void Main(string[] args) { char ch; Console.Write("Enter Character: "); ch = Console.ReadKey(true).KeyChar; //input char is hidden Console.WriteLine("Character = " + ch); Console.Write("Enter Character: "); ch = Console.ReadKey().KeyChar; //input char is visible Console.WriteLine("Character = " + ch); Console.ReadLine(); }
Example 2: Input character and display it.
static void Main(string[] args) { char ch; Console.Write("Enter Character: "); ch = Convert.ToChar(Console.ReadLine()); Console.WriteLine("Character = " + ch); Console.ReadLine(); }
S.No | Property | Description |
---|---|---|
char.IsDigit | ||
char.IsLetter | ||
char.IsLetterOrDigit | ||
char.IsLower | ||
char.IsNumber | ||
char.IsPunctuation | ||
char.IsSeparator | ||
char.IsSymbol | ||
char.IsUpper | ||
char.IsWhiteSpace |