In C#, Char.ConvertToUtf32 returns an int Unicode code point. Overloads accept a single BMP char, a high/low pair, or a string index at the start of a character.
For emoji and other non-BMP symbols, pass the pair (or string index) so both surrogates are included.
This is a static member of System.Char. You call it with the type name, such as Char.ConvertToUtf32(...) or char.ConvertToUtf32(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass a BMP char, a pair, or a string index.
C#
int cp1 = Char.ConvertToUtf32('A');
int cp2 = Char.ConvertToUtf32(emoji, 0);
Call
What it does
Char.ConvertToUtf32('A')
Returns 0x41.
Char.ConvertToUtf32(high, low)
Code point from a pair.
Char.ConvertToUtf32(s, i)
Code point starting at i.
Throws if a string index points at an incomplete or invalid pair.
Library declarations
C#
public static int ConvertToUtf32(char c);
public static int ConvertToUtf32(char highSurrogate, char lowSurrogate);
public static int ConvertToUtf32(string s, int index);
Parameters
Parameter
Description
c
BMP character.
highSurrogate, lowSurrogate
Valid pair.
s, index
String and start index.
Return Value
Return Value
Description
int
Unicode scalar value (code point).
C# Examples
Example 1 — Letter to Code Point
Convert A to its code point.
C#
using System;
class Program {
static void Main() {
int cp = Char.ConvertToUtf32('A');
Console.WriteLine(cp);
Console.WriteLine(cp.ToString("X"));
}
}
Output
65
41
How It Works
Single char. BMP overload.
Decimal 65. Same as (int)'A'.
Hex 41. Familiar Unicode notation.
Simple path. No surrogates involved.
Example 2 — Pair to 1F600
Convert an emoji string to its code point.
C#
using System;
class Program {
static void Main() {
string emoji = "\U0001F600";
int cp = Char.ConvertToUtf32(emoji, 0);
Console.WriteLine(cp.ToString("X"));
}
}
Output
1F600
How It Works
String index. Starts at the high surrogate.
Reads both units. Produces the full scalar.
Hex output. 1F600.
Validate first. IsSurrogatePair is a good guard in production.
Example 3 — From and To UTF-32
Convert both directions.
C#
using System;
class Program {
static void Main() {
int cp = 0x1F600;
string s = Char.ConvertFromUtf32(cp);
int back = Char.ConvertToUtf32(s, 0);
Console.WriteLine(back == cp);
Console.WriteLine(back.ToString("X"));
}
}
Output
True
1F600
How It Works
From UTF-32. Build the string.
Back to UTF-32. ConvertToUtf32 restores the value.