| title | char (C# Reference) | ||
|---|---|---|---|
| ms.date | 07/20/2015 | ||
| ms.prod | .net | ||
| ms.technology |
|
||
| ms.topic | article | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| ms.assetid | b51cf4fb-124c-4067-af48-afbac122b228 | ||
| caps.latest.revision | 27 | ||
| author | BillWagner | ||
| ms.author | wiwagn |
The char keyword is used to declare an instance of the xref:System.Char?displayProperty=nameWithType 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.
| Type | Range | Size | .NET Framework type |
|---|---|---|---|
char |
U+0000 to U+FFFF | Unicode 16-bit character | xref:System.Char?displayProperty=nameWithType |
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:
[!code-csharpcsrefKeywordsTypes#19]
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 xref:System.Char?displayProperty=nameWithType type provides several static methods for working with char values.
[!INCLUDECSharplangspec]
xref:System.Char
C# Reference
C# Programming Guide
C# Keywords
Integral Types Table
Built-In Types Table
Implicit Numeric Conversions Table
Explicit Numeric Conversions Table
Nullable Types
Strings