Bird
Raised Fist0
C Sharp (C#)programming~20 mins

Char type and Unicode behavior in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Unicode Char Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of char and Unicode code point conversion
What is the output of this C# code snippet?
C Sharp (C#)
char ch = '\u0041';
int code = ch;
Console.WriteLine(code);
A65
B41
CA
DSyntax error
Attempts:
2 left
💡 Hint
Remember that '\u0041' is a Unicode escape for a character, and casting char to int gives its code point.
❓ Predict Output
intermediate
2:00remaining
Output of char arithmetic with Unicode characters
What does this C# code print?
C Sharp (C#)
char ch = 'A';
ch = (char)(ch + 2);
Console.WriteLine(ch);
AB
BC
CD
DRuntime error
Attempts:
2 left
💡 Hint
Adding 2 to 'A' moves two characters forward in Unicode.
❓ Predict Output
advanced
2:00remaining
Output when using surrogate pairs in char arrays
What is the output of this C# code?
C Sharp (C#)
string s = "\U0001F600"; // Unicode emoji 😀
Console.WriteLine(s.Length);
A2
B1
C4
D0
Attempts:
2 left
💡 Hint
Some Unicode characters use two char units called surrogate pairs in .NET strings.
❓ Predict Output
advanced
2:00remaining
Behavior of char.IsSurrogate method
What does this C# code print?
C Sharp (C#)
char high = '\uD83D';
char low = '\uDE00';
Console.WriteLine(char.IsSurrogate(high));
Console.WriteLine(char.IsSurrogate(low));
AFalse\nFalse
BTrue\nFalse
CTrue\nTrue
DFalse\nTrue
Attempts:
2 left
💡 Hint
Both high and low surrogate halves are considered surrogate chars.
🧠 Conceptual
expert
2:00remaining
Understanding char and Unicode code points in C#
Which statement about C# char type and Unicode is TRUE?
AThe char type can store any Unicode character without needing surrogate pairs.
BA char represents a full Unicode code point, including those outside the Basic Multilingual Plane.
CC# strings store Unicode code points directly as 32-bit integers.
DA char is a 16-bit value representing a UTF-16 code unit, which may be a surrogate half for some characters.
Attempts:
2 left
💡 Hint
Think about how UTF-16 encoding works and how C# char relates to it.

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

  1. Step 1: Understand the char type

    The char type stores exactly one character, not multiple characters or numbers.
  2. Step 2: Recognize the syntax for char

    In C#, a char is written with single quotes, like 'A', representing a Unicode character.
  3. Final Answer:

    A single Unicode character enclosed in single quotes -> Option A
  4. 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

  1. Step 1: Check the syntax for char declaration

    In C#, a char must be assigned a single character enclosed in single quotes.
  2. 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.
  3. Final Answer:

    char letter = 'Z'; -> Option C
  4. 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

  1. Step 1: Understand char to int conversion

    Assigning a char to an int converts the character to its Unicode numeric value.
  2. Step 2: Find Unicode value of 'A'

    The Unicode (and ASCII) value of 'A' is 65, so code becomes 65.
  3. Final Answer:

    65 -> Option D
  4. 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

  1. Step 1: Check char assignment syntax

    Assigning a char requires single quotes, but double quotes were used, which is a string.
  2. Step 2: Validate other parts

    Casting char to int is valid, semicolons are present, and Console.WriteLine can print integers.
  3. Final Answer:

    Cannot convert string to char using double quotes -> Option A
  4. 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

  1. Step 1: Understand Unicode escape and character literal

    \u03A9 is the Unicode escape for Greek capital Omega, same as the character 'Ω'.
  2. Step 2: Compare the two chars

    Both c1 and c2 represent the same Unicode character, so the comparison returns true.
  3. Final Answer:

    True -> Option B
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard