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
✗ Incorrect
The C# char type is a 16-bit value representing a UTF-16 code unit.
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
✗ Incorrect
Characters outside the BMP require two char values called surrogate pairs.
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)
✗ Incorrect
Use char.IsHighSurrogate(c) to check for a high surrogate.
What encoding does C# char use internally?
AUTF-8
BASCII
CUTF-16
DUTF-32
✗ Incorrect
C# char stores UTF-16 code units.
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
✗ Incorrect
Characters outside the BMP need two char values (surrogate pairs) to be represented.
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.
Practice
(1/5)
1. What does the char type in C# represent?
easy
A. A single Unicode character enclosed in single quotes
B. A string of characters enclosed in double quotes
C. An integer number representing ASCII code
D. A floating-point number representing character code
Solution
Step 1: Understand the char type
The char type stores exactly one character, not multiple characters or numbers.
Step 2: Recognize the syntax for char
In C#, a char is written with single quotes, like 'A', representing a Unicode character.
Final Answer:
A single Unicode character enclosed in single quotes -> Option A
Quick Check:
char = single Unicode character [OK]
Hint: Remember: char holds one character in single quotes [OK]
Common Mistakes:
Confusing char with string type
Thinking char stores numbers directly
Using double quotes for char
2. Which of the following is the correct way to declare a char variable with the letter 'Z' in C#?
easy
A. char letter = "Z";
B. char letter = Z;
C. char letter = 'Z';
D. char letter = (char)"Z";
Solution
Step 1: Check the syntax for char declaration
In C#, a char must be assigned a single character enclosed in single quotes.
Step 2: Evaluate each option
char letter = "Z"; uses double quotes which is for strings, char letter = Z; misses quotes, char letter = (char)"Z"; tries casting a string which is invalid.
Final Answer:
char letter = 'Z'; -> Option C
Quick Check:
Single quotes for char = char letter = 'Z'; [OK]
Hint: Use single quotes for char, double quotes for string [OK]
Common Mistakes:
Using double quotes instead of single quotes
Assigning char without quotes
Casting string to char incorrectly
3. What is the output of the following C# code?
char c = 'A';
int code = c;
Console.WriteLine(code);
medium
A. Syntax error
B. A
C. 0
D. 65
Solution
Step 1: Understand char to int conversion
Assigning a char to an int converts the character to its Unicode numeric value.
Step 2: Find Unicode value of 'A'
The Unicode (and ASCII) value of 'A' is 65, so code becomes 65.
Final Answer:
65 -> Option D
Quick Check:
char 'A' to int = 65 [OK]
Hint: Casting char to int gives Unicode number [OK]
Common Mistakes:
Expecting character 'A' to print instead of number
Thinking char stores ASCII only, not Unicode
Assuming syntax error on implicit conversion
4. Identify the error in this code snippet:
char c = "B";
int code = (int)c;
Console.WriteLine(code);
medium
A. Cannot convert string to char using double quotes
B. Casting char to int is invalid
C. Missing semicolon after declaration
D. Console.WriteLine cannot print integers
Solution
Step 1: Check char assignment syntax
Assigning a char requires single quotes, but double quotes were used, which is a string.
Step 2: Validate other parts
Casting char to int is valid, semicolons are present, and Console.WriteLine can print integers.
Final Answer:
Cannot convert string to char using double quotes -> Option A
Quick Check:
char needs single quotes, not double [OK]
Hint: Use single quotes for char, double quotes cause error [OK]
Common Mistakes:
Using double quotes for char
Thinking casting char to int is wrong
Ignoring syntax errors in assignment
5. Given the code below, what will be the output?
char c1 = '\u03A9'; // Greek capital letter Omega
char c2 = 'Ω';
Console.WriteLine(c1 == c2);
hard
A. Compilation error
B. True
C. False
D. Runtime exception
Solution
Step 1: Understand Unicode escape and character literal
\u03A9 is the Unicode escape for Greek capital Omega, same as the character 'Ω'.
Step 2: Compare the two chars
Both c1 and c2 represent the same Unicode character, so the comparison returns true.
Final Answer:
True -> Option B
Quick Check:
Unicode escape equals character literal = True [OK]
Hint: Unicode escape and char literal can represent same character [OK]
Common Mistakes:
Assuming escape and literal differ
Expecting false due to different syntax
Thinking Unicode escape causes error
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.