0
0
C Sharp (C#)programming~5 mins

Char type and Unicode behavior in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the C# char type used for?
The char type in C# represents a single 16-bit Unicode character. It stores a UTF-16 code unit, which can represent most common characters.
Click to reveal answer
intermediate
How does C# char handle Unicode characters outside the Basic Multilingual Plane (BMP)?
Characters outside the BMP (code points above U+FFFF) are represented using a pair of char values called surrogate pairs. Each char holds one 16-bit code unit of the UTF-16 encoding.
Click to reveal answer
intermediate
What is a surrogate pair in Unicode?
A surrogate pair is two 16-bit char values that together represent a single Unicode character outside the BMP (above U+FFFF). The first is a high surrogate, the second a low surrogate.
Click to reveal answer
intermediate
How can you check if a char is a high surrogate or low surrogate in C#?
Use char.IsHighSurrogate(char c) to check for a high surrogate and char.IsLowSurrogate(char c) for a low surrogate.
Click to reveal answer
beginner
Why can't a single C# char always represent a full Unicode character?
Because char stores a UTF-16 code unit, some Unicode characters (those outside BMP) require two char values (surrogate pairs) to represent one character fully.
Click to reveal answer
What size is the C# char type?
A16 bits
B8 bits
C32 bits
D64 bits
Which of these represents a Unicode character outside the Basic Multilingual Plane in C#?
AA string of length 3
BA single <code>char</code>
CAn 8-bit byte
DA surrogate pair of two <code>char</code> values
How do you check if a char is a high surrogate in C#?
Achar.IsDigit(c)
Bchar.IsHighSurrogate(c)
Cchar.IsSurrogate(c)
Dchar.IsLowSurrogate(c)
What encoding does C# char use internally?
AUTF-8
BASCII
CUTF-16
DUTF-32
Why might a Unicode character need two char values in C#?
ABecause it is outside the BMP and requires surrogate pairs
BBecause <code>char</code> is 8-bit
CBecause it is a combining character
DBecause it is a control character
Explain how the C# char type represents Unicode characters, including those outside the Basic Multilingual Plane.
Think about UTF-16 encoding and surrogate pairs.
You got /4 concepts.
    Describe how to identify surrogate pairs in C# and why they are important.
    Focus on surrogate pair detection methods and their role.
    You got /4 concepts.