char (C# Reference)


Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

The char keyword is used to declare an instance of the System.Char structure that the .NET Framework uses to represent a Unicode character. The value of a Char object is a 16-bit numeric (ordinal) value.

Unicode characters are used to represent most of the written languages throughout the world.

TypeRangeSize.NET Framework type
charU+0000 to U+FFFFUnicode 16-bit characterSystem.Char

Constants of the char type can be written as character literals, hexadecimal escape sequence, or Unicode representation. You can also cast the integral character codes. In the following example four char variables are initialized with the same character X:

            char[] chars = new char[4];

            chars[0] = 'X';        // Character literal
            chars[1] = '\x0058';   // Hexadecimal
            chars[2] = (char)88;   // Cast from integral type
            chars[3] = '\u0058';   // Unicode

            foreach (char c in chars)
                Console.Write(c + " ");
            // Output: X X X X

A char can be implicitly converted to ushort, int, uint, long, ulong, float, double, or decimal. However, there are no implicit conversions from other types to the char type.

The System.Char type provides several static methods for working with char values.

For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.

C# Reference
C# Programming Guide
C# Keywords
Integral Types Table
Built-In Types Table
Implicit Numeric Conversions Table
Explicit Numeric Conversions Table
Nullable Types