In C#, Char.IsSurrogatePair returns true when two adjacent code units form a valid high+low surrogate pair.
Use it before calling ConvertToUtf32 on a string index, or when scanning text that may contain emoji.
This is a static member of System.Char. You call it with the type name, such as Char.IsSurrogatePair(...) or char.IsSurrogatePair(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass two chars, or a string and starting index.
C#
bool ok = Char.IsSurrogatePair(high, low);
bool also = Char.IsSurrogatePair(text, index);
Call
What it does
Char.IsSurrogatePair(high, low)
True if high+low is a valid pair.
Char.IsSurrogatePair(s, i)
True if s[i], s[i+1] form a pair.
False when order is wrong or either unit is not a surrogate.
Library declarations
C#
public static bool IsSurrogatePair(char highSurrogate, char lowSurrogate);
public static bool IsSurrogatePair(string s, int index);
Parameters
Parameter
Description
highSurrogate, lowSurrogate
Expected high then low.
s, index
String and start index for a possible pair.
Return Value
Return Value
Description
true
Valid surrogate pair.
false
Not a valid pair.
C# Examples
Example 1 — Emoji Pair
Confirm an emoji string starts with a pair.
C#
using System;
class Program {
static void Main() {
string emoji = "\U0001F600";
Console.WriteLine(Char.IsSurrogatePair(emoji, 0));
Console.WriteLine(emoji.Length);
}
}
Output
True
2
How It Works
Pair at 0. High and low present.
Length 2. Two UTF-16 units.
Ready for UTF-32. Safe to convert.
One glyph. Still one visible character conceptually.
Example 2 — Low Then High Fails
Swap units and watch the check fail.
C#
using System;
class Program {
static void Main() {
string emoji = "\U0001F600";
char high = emoji[0];
char low = emoji[1];
Console.WriteLine(Char.IsSurrogatePair(high, low));
Console.WriteLine(Char.IsSurrogatePair(low, high));
}
}
Output
True
False
How It Works
Correct order. High then low works.
Swapped fails. Low then high is invalid.
Order matters. Pair rules are strict.
Do not reverse. Keep the natural string order.
Example 3 — Pair to UTF-32
Validate then convert to a code point.
C#
using System;
class Program {
static void Main() {
string emoji = "\U0001F600";
if (Char.IsSurrogatePair(emoji, 0)) {
int cp = Char.ConvertToUtf32(emoji, 0);
Console.WriteLine(cp.ToString("X"));
}
}
}
Output
1F600
How It Works
Guard first. IsSurrogatePair before convert.
UTF-32 value. ConvertToUtf32 yields the code point.