Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C#
C# Reference
C# Keywords
Types
Value Types
 char
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
C# Language Reference
char (C# Reference)

The char keyword is used to declare a Unicode character in the range indicated in the following table. Unicode characters are 16-bit characters used to represent most of the known written languages throughout the world.

Type Range Size .NET Framework type

char

U+0000 to U+ffff

Unicode 16-bit character

System.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. All of the following statements declare a char variable and initialize it with the character X:

        char char1 = 'Z';        // Character literal
char char2 = '\x0058';   // Hexadecimal
char char3 = (char)88;   // Cast from integral type
char char4 = '\u0058';   // Unicode

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.

For more information, see the following sections in the C# Language Specification:

  • 1.3 Types and Variables

  • 2.4.4.4 Character Literals

  • 4.1.5 Integral Types

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker