Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 13:05, 19 August 2025 by Dylan (talk | contribs) (add: casting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The char data type in C Sharp is used to store a single character value, usually in a variable.

It is the base unit for the string data type (see C Sharp string).

See Char for general information about the uses and memory layout of a character data type.

Values of type char take up 2 bytes in memory in C#.

This means they can store 65536 different character values.

char a = 'a';
char b = '&';
string c = "hello world";
char d = c[4]; // 'o'

To cast to a char, you can use the casting operator or the Convert.ToChar method:

sbyte a = 65;
char b = (char)a; // 'A'
char c = Convert.ToChar(a); // 'A'