← Back to C# Course | Chapter 2: Variables & Types | Lesson 4 of 7

The char Type

A char holds exactly one letter, digit, or symbol, like a single tile in a word game. You write it with single quotes.

In this page:

  1. The char Type
Syntax
csharp
char variableName = 'A';
int code = (int)variableName;
bool isDigit = char.IsDigit(variableName);

The char Type

A char represents a single UTF-16 character and is written with single quotes, like A. Characters can be compared, cast to their underlying numeric code point, and combined into strings. Double quotes are reserved for string, not char.

Note: Casting a char to int gives you its Unicode code point.

Example: The char Type

markup
using System;

class Program
{
    static void Main(string[] args)
    {
        char letter = 'A';
        char digit = '7';

        Console.WriteLine(letter);
        Console.WriteLine((int)letter);
        Console.WriteLine(char.IsDigit(digit));
    }
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Using double quotes for a char, such as char c = "A";, when a char needs single quotes A.
  2. Expecting a + 1 to be a char, when the result is an int and needs a cast to char.
  3. Trying to put more than one character in a char literal like ab.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.