In C#, a char is one UTF-16 code unit. Characters beyond the Basic Multilingual Plane need two chars: a high surrogate and a low surrogate.
Char.IsSurrogate returns true if a code unit is either kind of surrogate. Ordinary letters like 'A' return false.
This is a static member of System.Char. You call it with the type name, such as Char.IsSurrogate(...) or char.IsSurrogate(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass a single char (one code unit) to test.
C#
bool ok = Char.IsSurrogate(c);
Call
What it does
Char.IsSurrogate(c)
True if c is any surrogate.
Char.IsSurrogate(s, i)
Tests s[i].
Use IsHighSurrogate / IsLowSurrogate / IsSurrogatePair for more detail.
Library declarations
C#
public static bool IsSurrogate(char c);
public static bool IsSurrogate(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 or low surrogate.
false
Not a surrogate.
C# Examples
Example 1 — Letter Is Not Surrogate
Show that A is not a surrogate.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(Char.IsSurrogate('A'));
Console.WriteLine(Char.IsHighSurrogate('A'));
}
}
Output
False
False
How It Works
BMP letter. A fits in one char.
Not surrogate. IsSurrogate is false.
Not high. IsHighSurrogate also false.
Everyday text. Most letters never need surrogates.
Example 2 — Surrogate From Emoji String
Inspect the first code unit of a non-BMP character.
C#
using System;
class Program {
static void Main() {
string emoji = "\U0001F600"; // 😀
char first = emoji[0];
Console.WriteLine("len: " + emoji.Length);
Console.WriteLine("surrogate: " + Char.IsSurrogate(first));
Console.WriteLine("high: " + Char.IsHighSurrogate(first));
}
}
Output
len: 2
surrogate: True
high: True
How It Works
Two chars. The emoji needs a surrogate pair.
First unit. Index 0 is the high surrogate.
IsSurrogate true. It is a surrogate code unit.
IsHigh true. Confirms which half you have.
Example 3 — Count Surrogate Units
Count how many surrogate code units appear.
C#
using System;
class Program {
static void Main() {
string s = "A\U0001F600B";
int n = 0;
foreach (char ch in s) {
if (Char.IsSurrogate(ch)) n++;
}
Console.WriteLine(n);
}
}
Output
2
How It Works
Mixed string. Letters plus one emoji.
Two surrogates. High and low units.
Letters ignored. A and B are not surrogates.
Unit count. Not the same as counting visible glyphs.
Frequently Asked Questions
A UTF-16 code unit used in pairs to encode Unicode beyond U+FFFF.
No.
Many emoji need a high and low surrogate—two chars.
IsHighSurrogate, IsLowSurrogate, IsSurrogatePair.
Only when working with non-BMP characters carefully.