The char Type
Single characters in C#.
The char Type is a free C# Academy lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C# Academy learning path, and your progress syncs across the web and the CoddyKit app. The C# Academy course includes 4 lessons in total.
What Is a char?
In C#, char represents a single Unicode character, like a letter, digit, or symbol.
You write a char literal using single quotes, not double quotes. Double quotes are reserved for strings.
A char always holds exactly one character.
char letter = 'A';
char digit = '7';
char symbol = '#';Printing a char
You can print a char just like any other value with Console.WriteLine.
This complete program declares a char and prints it. Notice the single quotes around the character.
class Program
{
static void Main()
{
char grade = 'B';
System.Console.WriteLine(grade);
}
}char vs string
A char is one character; a string is a sequence of characters.
Single quotes make a char. Double quotes make a string, even if it holds just one letter.
So 'A' and "A" are different types.
char c = 'A';
string s = "A";char Has a Numeric Code
Each char maps to a number called its Unicode code point.
If you cast a char to int, you see that number. For example, 'A' is 65 and 'a' is 97.
This is why characters can be compared and ordered.
class Program
{
static void Main()
{
char c = 'A';
int code = (int)c;
System.Console.WriteLine(code);
}
}From Number Back to char
You can also cast an int back into a char.
Casting the number 66 to a char gives 'B'. This lets you build characters from their codes.
class Program
{
static void Main()
{
int code = 66;
char c = (char)code;
System.Console.WriteLine(c);
}
}Reading a char From a string
A string lets you access individual characters using square brackets and an index.
Indexes start at 0, so text[0] is the first character. Each item you read this way is a char.
class Program
{
static void Main()
{
string text = "Code";
char first = text[0];
System.Console.WriteLine(first);
}
}Comparing chars
Because each char has a numeric code, you can compare them with <, >, and ==.
For example, 'a' < 'b' is true because 97 is less than 98. This is useful for sorting and checking ranges.
bool result = 'a' < 'b';
// result is trueCommon Escape Sequences
Some characters need an escape sequence inside single quotes.
A newline is '\n', a tab is '\t', and a single quote is '\''. The backslash starts the escape.
char newline = '\n';
char tab = '\t';
char quote = '\'';char in a Variable Type
You can use var and the compiler infers the type from the literal.
Because the value uses single quotes, letter becomes a char automatically. The behavior is the same as writing char explicitly.
class Program
{
static void Main()
{
var letter = 'Z';
System.Console.WriteLine(letter);
}
}Default char Value
The default value of a char is '\0', the null character with code 0.
It is not a space or an empty value. If you create a char without assigning it a meaningful character, it starts as this null character.
char c = default;
int code = (int)c;
// code is 0char to string
To turn a char into a one-character string, call ToString on it.
This is handy when an API needs a string but you only have a single char.
class Program
{
static void Main()
{
char c = 'X';
string s = c.ToString();
System.Console.WriteLine(s);
}
}Quick Check
Test your understanding of the char type.
Recap
A char holds one Unicode character and uses single quotes.
Each char has a numeric code, so you can cast between char and int and compare characters. You read a char from a string by index, and turn it into a string with ToString.
Learn C# with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 93
- Lessons
- 346
Frequently Asked Questions
Is the “The char Type” lesson free?
Yes — the full text of “The char Type” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C# Academy course, upgrade to CoddyKit PRO. The C# Academy course includes 4 lessons in total.
What will I learn in “The char Type”?
Single characters in C#. You practise C# Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C# Academy?
No prior experience is required. C# Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
How long does the “The char Type” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C# Academy lesson?
Yes. Every C# Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.