In C#, Char.IsHighSurrogate returns true for high-surrogate code units (roughly U+D800–U+DBFF).
A complete non-BMP character is a high surrogate followed by a low surrogate. Alone, a high surrogate is incomplete.
This is a static member of System.Char. You call it with the type name, such as Char.IsHighSurrogate(...) or char.IsHighSurrogate(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass one code unit to test.
C#
bool ok = Char.IsHighSurrogate(c);
Call
What it does
Char.IsHighSurrogate(c)
True if c is a high surrogate.
Char.IsHighSurrogate(s, i)
Tests s[i].
Pair with IsLowSurrogate on the next index.
Library declarations
C#
public static bool IsHighSurrogate(char c);
public static bool IsHighSurrogate(string s, int index);
Parameters
Parameter
Description
c
Code unit to test.
s, index
Optional string index overload.
Return Value
Return Value
Description
true
High surrogate.
false
Not a high surrogate.
C# Examples
Example 1 — First Unit of Emoji
Identify the high surrogate in an emoji string.
C#
using System;
class Program {
static void Main() {
string emoji = "\U0001F600";
Console.WriteLine(Char.IsHighSurrogate(emoji, 0));
Console.WriteLine(Char.IsLowSurrogate(emoji, 1));
}
}
Output
True
True
How It Works
Index 0 high. First half of the pair.
Index 1 low. Second half.
String overload. No need to copy chars first.
Valid pair shape. High then low.
Example 2 — Ordinary Letter
Show that Z is not a high surrogate.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(Char.IsHighSurrogate('Z'));
Console.WriteLine(Char.IsSurrogate('Z'));
}
}
Output
False
False
How It Works
BMP char. Z needs no pair.
Not high. IsHighSurrogate false.
Not surrogate. Broader test also false.
Simple contrast. Everyday letters stay simple.
Example 3 — Skip Pair as Two Units
Advance by 2 when a high surrogate is found.
C#
using System;
class Program {
static void Main() {
string s = "X\U0001F600Y";
int i = 0;
while (i < s.Length) {
if (Char.IsHighSurrogate(s, i)) {
Console.WriteLine("pair at " + i);
i += 2;
} else {
Console.WriteLine("char " + s[i]);
i++;
}
}
}
}
Output
char X
pair at 1
char Y
How It Works
Manual walk. Handle pairs explicitly.
Step by two. After a high surrogate, skip the low one.