C# char (Character)

The char data type represents a single character. A char is a 16-bit Unicode character, and it must be enclosed in single quotes, such as 'A'.

Key Concepts

  • The char type stores a single character, which can be any letter, number, or symbol.
  • It uses Unicode, so it supports a wide range of characters from many languages.
  • Strings in C# are made up of multiple char elements.

Example of Using a char

Code Example

// Declare a character variable
char myChar = 'A';

// Output the character to the console
Console.WriteLine(myChar);

Output:

A

Code Explanation: The char variable myChar is initialized with the character 'A'. It is printed using the Console.WriteLine() method.

Output Explanation: The character 'A' is displayed on the console, which is the value assigned to myChar.