In C#, Char.Parse converts a string into a char. The string must contain exactly one character.
If the string is null, empty, or longer than one character, Parse throws. Prefer TryParse when input might be wrong.
This is a static member of System.Char. You call it with the type name, such as Char.Parse(...) or char.Parse(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass a one-character string.
C#
char c = Char.Parse("A");
Call
What it does
Char.Parse("A")
Returns 'A'.
Surrogate pairs are two chars—Parse cannot turn an emoji string of length 2 into one char.
Library declarations
C#
public static char Parse(string s);
Parameters
Parameter
Description
s
Required. Must have Length == 1.
Return Value
Return Value
Description
char
The single character from the string.
C# Examples
Example 1 — Parse a Letter
Convert "A" to char A.
C#
using System;
class Program {
static void Main() {
char c = Char.Parse("A");
Console.WriteLine(c);
Console.WriteLine(Char.IsLetter(c));
}
}
Output
A
True
How It Works
Length one. "A" is valid input.
Char result. Variable holds A.
IsLetter true. Parsed value behaves like any char.
Strict API. Wrong lengths throw.
Example 2 — Parse "7"
Turn a digit string into a char.
C#
using System;
class Program {
static void Main() {
char c = Char.Parse("7");
Console.WriteLine(c);
Console.WriteLine(Char.GetNumericValue(c));
}
}
Output
7
7
How It Works
Digit string. One character "7".
Parse to char. Still a character, not an int.
Numeric value. GetNumericValue yields 7.
Two steps. Parse then interpret.
Example 3 — Show Failure Path Idea
Demonstrate that long strings are invalid for Parse—use TryParse instead.
C#
using System;
class Program {
static void Main() {
string bad = "AB";
bool ok = Char.TryParse(bad, out char c);
Console.WriteLine("TryParse AB: " + ok);
Console.WriteLine("Parse works for: " + Char.Parse("Z"));
}
}
Output
TryParse AB: False
Parse works for: Z
How It Works
Too long. "AB" has length 2.
TryParse false. No exception.
Parse Z. Length-1 still works.
Safer habit. Reach for TryParse on untrusted input.
Frequently Asked Questions
Exactly 1.
Parse throws; TryParse returns false.
Most emoji are length 2 (surrogate pair); Parse cannot return one char for them.