Top 50 Advanced C# Interview Questions & Answers with Examples
A complete list of 50 advanced C# interview questions covering threading, performance, memory, delegates, reflection, generics, LINQ, async/await, Span
1. What is SOLID? Explain with C# examples.
Single Responsibility
Open/Closed
Liskov Substitution
Interface Segregation
Dependency Inversion
Example (Single Responsibility):
2. Explain Dependency Injection with example.
Passing dependencies instead of creating them inside a class.
3. What are Records in C#?
Immutable reference types introduced in C# 9.
4. What is the difference between record and class?
- Record: immutable, value-based equality
- Class: mutable reference-based equality
5. What is Span<T>? Why is it used?
A stack-only, fast, memory-safe type for slicing arrays without copying.
6. What is Memory<T>?
Similar to Span<T> but allowed in async methods.
Memory<byte> mem = new byte[100];
7. What is Reflection? Provide an example.
Inspecting assemblies at runtime.
8. What is Emit in C#?
Used to generate IL code at runtime.
9. Explain Covariance & Contravariance.
10. What is Thread-Safety?
Ensuring shared data is safe across threads.
lock(_lockObj) { count++; }
11. What is Deadlock? Example?
Two threads wait forever for each other's locks.
12. What is SemaphoreSlim?
Used to limit concurrent threads.
await semaphore.WaitAsync();
13. What is ReaderWriterLockSlim?
Allows multiple readers but only one writer.
14. Explain async/await state machine.
Compiler breaks async method into states using IAsyncStateMachine.
15. What is ConfigureAwait(false)?
Avoids capturing UI context → better performance.
16. Explain Parallel.ForEach with example.
Used for multi-threaded loops.
17. What is CancellationToken?
Used to cancel async tasks.
18. What is immutable class?
Class whose fields cannot be modified.
19. Explain Custom Attributes with example.
20. What is Middleware in .NET Core?
Pipeline components that handle HTTP requests.
21. What is Memory Leak in C#?
Occurs when objects are still referenced but unused.
22. What is GC Generation?
3 generations – 0,1,2 for optimized memory cleanup.
23. Explain IDisposable & using pattern.
using(var con = new SqlConnection()) {}
24. What is WeakReference?
Allows object to be collected even if referenced.
25. What is Polymorphism with abstract classes?
26. What is Method Hiding?
public new void Show() {}
27. What is Expression Tree?
28. What is IQueryable?
Converts LINQ query to SQL.
29. What is Deferred Execution?
Query executed when enumerated.
30. What is PLINQ?
Parallel LINQ:
31. What is AutoMapper?
Object-to-object mapping library.
32. What is MediatR?
Mediator pattern library for CQRS.
33. Explain CQRS.
Separates “Read” and “Write” operations.
34. What is Minimal API (.NET 6+)?
35. What is Dependency Inversion Principle?
High-level modules should not depend on low-level modules.
36. What are Nullable Reference Types?
Avoid null reference exceptions.
string? name = null;
37. What is Pattern Matching?
38. What is yield return?
Used for lazy iteration.
yield return item;
39. What is BlockingCollection?
Thread-safe producer-consumer collection.
40. What is ConcurrentDictionary?
Thread-safe dictionary type.
41. What is Mutex?
Used for inter-process locking.
42. What is StopWatch?
High-performance timer.
var sw = Stopwatch.StartNew();
43. What is BenchmarkDotNet?
Library for performance benchmarking.
44. What is AOT Compilation?
Ahead-of-time compilation for performance (.NET 7+).
45. What is Source Generator in C#?
Compile-time code generation.
46. What is IL Code?
Intermediate Language executed by CLR.
47. What is JIT Compiler?
Just-in-Time compiler converting IL to machine code.
48. What is Reflection.Emit?
Generates IL dynamically at runtime.
49. What is Dynamic Keyword?
50. What is Repository Pattern?