पाठ 25 / 25
C# Revision and Interview Questions
Recall core C# and .NET concepts for exams and interviews.
Cheat sheet
Platform: C# → IL → CLR JIT → native; BCL; .NET 10 LTS with C# 14; .NET Framework is legacy. Types: value types copy data, reference types copy references; decimal for money; strings immutable. Flow: no switch fall-through; switch expressions must be exhaustive; patterns (type, property, relational, list). Methods: by value default; ref, out, in, params; optional and named arguments. OOP: properties, init, required, primary constructors; single inheritance, many interfaces; virtual/override/abstract/sealed; records with value equality and with. Types II: reified generics with constraints; int? and nullable reference types with ?., ??, ??=; Func, Action, lambdas, closures, events. Collections: List, Dictionary, HashSet, Queue, PriorityQueue; LINQ is deferred; yield return iterators. Async: Task, await frees threads, WhenAll, CancellationToken, no .Result, no async void; lock/Lock, Interlocked, concurrent collections. Runtime: generational GC, IDisposable + using; exceptions with throw;; Span<T>, StringBuilder, avoid boxing.
Common interview questions
Answer each in two or three sentences, with a small example.
1. Value type vs reference type: what happens on assignment?
2. class vs struct vs record: when would you use each?
3. Abstract class vs interface?
4. What are nullable reference types and how do ?. and ?? help?
5. What is deferred execution in LINQ?
6. What does await actually do with the current thread?
7. Why should you avoid .Result and async void?
8. How does the .NET garbage collector work, and what is IDisposable for?
9. throw vs throw ex?
10. What problem does Span<T> solve?Explain the why, not just the what
"Records compare by value" is a fact; "so I use them for DTOs and as dictionary keys, but not for EF Core entities that need identity" is an answer that shows judgement.
त्वरित जाँच: Which statement about `async void` methods is true?
- They are the recommended return type for async library methods
- They run synchronously
- They return a Task automatically
- Their exceptions cannot be caught by the caller, so use them only for event handlers
Answer
Their exceptions cannot be caught by the caller, so use them only for event handlers — Callers cannot await async void methods or catch their exceptions; prefer Task-returning methods.