C# Char GetTypeCode() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Char

Definition

In C#, GetTypeCode returns TypeCode.Char for any char value. It is part of the IConvertible pattern used by some older conversion helpers.

Beginners rarely need it day to day, but it appears when code inspects runtime type codes for mixed values.

This is an instance member of System.Char. You call it on a char value with a dot, such as c.GetTypeCode(...). A char holds one 16-bit UTF-16 code unit.

Syntax

Call on a char; the answer is always TypeCode.Char.

C#
char c = 'A';
TypeCode tc = c.GetTypeCode();
CallWhat it does
c.GetTypeCode()Returns TypeCode.Char.

Every char returns the same TypeCode; the value of the character does not change it.

Library declarations
C#
public TypeCode GetTypeCode();

Parameters

ParameterDescription
NoneGetTypeCode() takes no parameters.

Return Value

Return ValueDescription
TypeCode.CharThe type code for System.Char.

C# Examples

Example 1 — Print TypeCode.Char

Call GetTypeCode on a letter and print it.

C#
using System;

class Program {
    static void Main() {
        char c = 'A';
        TypeCode tc = c.GetTypeCode();
        Console.WriteLine(tc);
        Console.WriteLine(tc == TypeCode.Char);
    }
}

How It Works

  1. Instance call. Any char exposes GetTypeCode.
  2. Enum name. Printing the TypeCode shows Char.
  3. Equality check. Compare against TypeCode.Char.
  4. Not classification. This does not say whether A is a letter—that is IsLetter.

Example 2 — Digits Are Still TypeCode.Char

Show that a digit character still reports Char.

C#
using System;

class Program {
    static void Main() {
        char d = '5';
        Console.WriteLine(d.GetTypeCode());
        Console.WriteLine(Char.IsDigit(d));
    }
}

How It Works

  1. Type vs category. TypeCode is Char; IsDigit answers the Unicode question.
  2. Both true ideas. It is a char value that happens to be a digit.
  3. Pick APIs carefully. Use GetTypeCode for type codes, Is* for character classes.
  4. Beginner trap. Do not expect TypeCode.Int32 for digit characters.

Example 3 — Branch on TypeCode

Use a switch to recognize Char among sample values.

C#
using System;

class Program {
    static void Main() {
        char c = 'Z';
        switch (c.GetTypeCode()) {
            case TypeCode.Char:
                Console.WriteLine("Handled as Char: " + c);
                break;
            default:
                Console.WriteLine("Other");
                break;
        }
    }
}

How It Works

  1. Switch on enum. TypeCode fits cleanly in a switch.
  2. Char arm runs. Our value is a character.
  3. Print the glyph. The case body can still use the original char.
  4. Rare pattern. Modern code usually knows the type statically.

Frequently Asked Questions

Always TypeCode.Char.
No. A, 5, and space all report TypeCode.Char.
Mostly when working with IConvertible or mixed-type helpers.
Use IsDigit, IsLetter, GetUnicodeCategory, and similar methods.
No. It is an instance method on the char value.

Next: GetUnicodeCategory()

Return the UnicodeCategory enum value for a character with System.Char.

GetUnicodeCategory() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful