C# Quiz
Thirty questions covering the whole course. Choose an answer for each, then press Check answers at the bottom to see your score and an explanation for every question.
1. What does the C# compiler turn your source code into?
The JIT compiler in the runtime turns IL into native code; Native AOT can also do it ahead of time (lesson 01).
2. How do you run a single file called app.cs with .NET 10?
Single-file apps need no project file (lessons 03–04).
3. What does Console.WriteLine(7 / 2); print?
Both operands are integers, so the fraction is discarded (lesson 08).
4. Which type should you use for money?
decimal stores base-10 values exactly, so 0.1 + 0.2 is exactly 0.3 (lesson 08).
5. What does Math.Round(2.5) return by default?
The default is banker's rounding: halves round to the nearest even number. Pass MidpointRounding.AwayFromZero for 3 (lesson 08).
6. Why is int.TryParse usually better than int.Parse for user input?
(lesson 09)
7. What is the value of name ?? "guest" when name is null?
?? returns the right-hand side when the left is null (lesson 10).
8. What happens if a case in a C# switch statement has no break before the next case?
C# forbids implicit fall-through (lesson 13).
9. Which loop always runs its body at least once?
The condition is checked after each pass (lesson 14).
10. What does name.ToUpper(); on its own line do to name?
You need name = name.ToUpper(); (lesson 16).
11. In $"{price,8:F2}", what does 8 mean?
The full form is {value,alignment:format} (lesson 18).
12. What's the difference between ref and out parameters?
(lesson 22)
13. What is values[^1]?
^n counts from the end (lesson 30).
14. Which collection should you choose to look values up by a key quickly?
(lesson 28)
15. What happens if you remove items from a List inside a foreach over that same list?
Use RemoveAll, a backwards for loop, or build a new list (lesson 27).
16. After var b = a; where a is an object of a class, what happens when you change b.Name?
Classes are reference types (lessons 07 and 31). A struct would be copied instead (lesson 40).
17. What does { get; private set; } on a property mean?
(lesson 33)
18. What does the C# 14 field keyword refer to inside a property accessor?
It lets you add logic like validation without declaring a separate field (lesson 33).
19. Which statement about static members is true?
(lesson 34)
20. For a method to be overridden in a derived class, the base method must be marked…
Methods aren't virtual by default in C# (lesson 37).
21. What's a key difference between an abstract class and an interface?
(lessons 38–39)
22. Two records new Point(1, 2) and new Point(1, 2) are compared with ==. The result is…
(lesson 40)
23. Why does [Flags] matter on an enum like Permissions.Read | Permissions.Write?
Each member should also have its own bit value: 1, 2, 4, 8… (lesson 41).
24. With nullable reference types enabled, what does string? mean?
(lesson 43)
25. Which pattern matches an array whose first element is 1, whatever its length (at least one element)?
.. matches any number of elements; [1, _] requires exactly two (lesson 44).
26. What does where T : IComparable<T> do in a generic method?
A constraint (lesson 45).
27. When does a LINQ query like numbers.Where(n => n > 5) actually run?
Deferred execution (lesson 49).
28. What's the right way to rethrow a caught exception while keeping its original stack trace?
throw ex; resets the stack trace (lesson 52).
29. What does a using declaration such as using var file = new StreamWriter("a.txt"); guarantee?
(lesson 53)
30. Two independent async downloads each take 1 second. How do you run them so the total is about 1 second?
Starting a task returns immediately; awaiting them together lets them overlap (lesson 57).
How did you do?
- 27–30: excellent — you've got a solid grasp of C#. Try the final project's challenges.
- 20–26: good — revisit the lessons mentioned in the explanations you missed.
- Below 20: work through the exercises and re-read the parts of the course that felt shaky, then try again.