Learn Quiz

C# Quiz

Test your C# knowledge. — 8 questions

Question 1 of 8 Score: 0

About the C# Quiz

Test your C# knowledge. This quiz has 8 multiple-choice questions. Each question has one correct answer, and you see an explanation straight after you answer, so you learn from every question — including the ones you get wrong. There is no time limit and nothing to sign up for; your answers are not stored.

The questions follow the material in the C# Fundamentals guide and the C# cheatsheet. Read them first if you want to prepare, or take the quiz cold to find the gaps in what you know.

Questions in this quiz

Preview the questions below. Each answer and its explanation are hidden until you choose to reveal them, so you can still take the quiz above without spoilers.

1. What is the correct way to declare a nullable string in C#?

  1. nullable<string> s = null;
  2. string? s = null;
  3. string s = null;
  4. Optional<string> s = null;
Show answer

Answer: B. string? s = null;
C# uses the ? suffix for nullable reference types: string? s = null;

2. Which LINQ method filters elements based on a condition?

  1. Select
  2. OrderBy
  3. Where
  4. GroupBy
Show answer

Answer: C. Where
Where(predicate) filters a sequence, returning only elements that satisfy the predicate.

3. What does the ?? operator do in C#?

  1. Checks equality of two values
  2. Returns the left value if not null, otherwise the right
  3. Casts the left value to the right type
  4. Multiplies two nullable numbers
Show answer

Answer: B. Returns the left value if not null, otherwise the right
?? is null-coalescing: a ?? b returns a if a is not null, otherwise returns b.

4. What should an async method return instead of void?

  1. async
  2. void
  3. Task
  4. Thread
Show answer

Answer: C. Task
async methods must return Task or Task<T>. async void cannot be awaited and silently swallows exceptions.

5. Which symbol is used for inheritance in C#?

  1. extends
  2. implements
  3. inherits
  4. :
Show answer

Answer: D. :
C# uses the colon : for both inheritance (class Dog : Animal) and interface implementation.

6. What can foreach iterate over?

  1. Only arrays
  2. Only List<T>
  3. Any IEnumerable<T>
  4. Only strings
Show answer

Answer: C. Any IEnumerable<T>
foreach works on any type implementing IEnumerable<T>: arrays, lists, and custom collections.

7. What is a record type in C#?

  1. A database record
  2. An immutable reference type with value-based equality
  3. A mutable struct
  4. An enum with named values
Show answer

Answer: B. An immutable reference type with value-based equality
Records are reference types with positional properties and structural equality, ideal for immutable data models.

8. Which access modifier limits visibility to the declaring class only?

  1. protected
  2. internal
  3. private
  4. sealed
Show answer

Answer: C. private
private members are only accessible within the class that declares them.

How to use this quiz

  • Answer every question before reading the explanations below — retrieving an answer from memory is what makes it stick.
  • Note the questions you missed and revisit the matching section of the guide or cheatsheet.
  • Retake the quiz a day or two later. Spaced repetition is one of the most reliable ways to remember technical details.

Related