📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

377 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.

Phase 5 — CLR and .NET Runtime Internals

How .NET runs your code: the CLR, assemblies, JIT and AOT, runtime type layout and dispatch, the Roslyn compilation pipeline, and garbage collection.

  1. How does virtual method dispatch work in the CLR, and what does a virtual call cost compared with a direct call?

    Vtable slots in the MethodTable, the instruction sequence of a virtual call, override versus new, sealed and devirtualisation.

    Senior Theory Runtime Execution Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  2. How does interface method dispatch work in the CLR, and why can it be slower than virtual dispatch?

    Interface maps, virtual stub dispatch (indirection cells, dispatch and resolve stubs), default interface methods, constrained calls on structs.

    Senior Theory Runtime Execution Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  3. How does reflection work internally in .NET, why is it slow, and what are the faster alternatives?

    RuntimeType and member caches, Invoke costs and the .NET 7/8 invoker improvements, delegates, compiled expressions, UnsafeAccessor and source generators.

    Senior Theory Runtime Execution Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  4. How does the Roslyn compiler work, and how would you use the Roslyn APIs (syntax trees, semantic model, compilation) in your own tools?

    Roslyn's phases, immutable syntax trees, Compilation and SemanticModel, IOperation, emit, the compiler server and using the APIs to build tools.

    Senior Theory Compilation Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  5. How do you author a source generator in .NET, and how should the generator project be set up and packaged?

    Source generator authoring: IIncrementalGenerator, project setup (netstandard2.0, analyser references), post-initialisation output, debugging, packaging and pitfalls.

    Senior Coding Compilation Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  6. What makes a source generator incremental, and how do you keep a generator from slowing down the IDE?

    Incremental pipelines, caching and equality, ForAttributeWithMetadataName, avoiding symbols and syntax in models, and measuring generator performance.

    Senior Theory Compilation Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  7. How do you write a Roslyn analyser, and how do you test it and ship it to a team?

    Authoring DiagnosticAnalyzer: descriptors, registration actions, concurrency, generated code, testing with the Roslyn testing packages, severity configuration and packaging.

    Senior Coding Compilation Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  8. How do you write a Roslyn code fix provider, and what makes a code fix safe to apply across a whole solution?

    CodeFixProvider authoring: FixableDiagnosticIds, RegisterCodeFixesAsync, CodeAction with equivalence keys, syntax editing with trivia, Fix All and testing.

    Senior Coding Compilation Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  9. What are the options for build-time code generation in .NET, and how do you choose between source generators, MSBuild tasks, T4 templates and IL weaving?

    Comparing source generators, MSBuild-generated files (gRPC, OpenAPI), T4, IL weaving and interceptors for build-time code generation, with trade-offs.

    Senior Architecture Compilation Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  10. How does generational garbage collection work in .NET, and why does it make most collections cheap?

    The generational hypothesis, Gen 0/1/2, promotion, card tables and write barriers, regions, and mark-sweep-compact.

    Mid-Level Theory Garbage Collection Β· πŸ”— 4 follow-ups Β· πŸ›  1 real-world
  11. What happens during a Gen 0 allocation and collection in .NET, and how do you reduce Gen 0 GC frequency?

    Allocation contexts and bump-pointer allocation, the Gen 0 budget, what triggers a Gen 0 GC, allocation rate metrics and reducing allocations.

    Mid-Level Theory Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  12. What is the role of Gen 1 in the .NET GC, and what is the "mid-life crisis" problem?

    Gen 1 as a buffer between short- and long-lived objects, Gen 1 GCs, objects that die soon after reaching Gen 2, and how to fix mid-life lifetimes.

    Senior Theory Garbage Collection Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  13. What is a Gen 2 (full) garbage collection in .NET, what triggers it, and how do you investigate frequent Gen 2 GCs?

    Full GCs, triggers (budget, LOH allocation, induced, low memory), blocking versus background, compaction, and a method to diagnose frequent Gen 2 collections.

    Senior Debugging Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  14. What is the Large Object Heap (LOH) in .NET, and how do you find and fix LOH fragmentation and churn?

    The 85,000-byte threshold, LOH collection with Gen 2, no compaction by default, fragmentation, churn, GCLOHThreshold and fixes such as pooling and streaming.

    Senior Debugging Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  15. What is the Pinned Object Heap (POH), and when should you allocate pinned arrays instead of using fixed or GCHandle?

    Pinning, why it fragments the heap, the POH (.NET 5), GC.AllocateArray with pinned: true, its restrictions and typical uses such as I/O buffer pools.

    Senior Theory Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  16. What is Workstation GC in .NET, when is it the default, and when would you choose it over Server GC?

    Workstation GC: single heap, background GC on by default, non-concurrent option, defaults per app type, and choosing it for desktop, tools and dense containers.

    Mid-Level Theory Garbage Collection Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  17. What is Server GC in .NET, how does DATAS change it in .NET 9 and later, and how do you tune it in containers?

    Server GC heaps and threads, throughput versus memory, DATAS dynamic heap count (default with Server GC since .NET 9), and container settings such as GCHeapHardLimit and GCHeapCount.

    Senior Theory Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  18. What is the difference between background GC and the older concurrent GC in .NET, and how do GC latency modes affect pauses?

    Concurrent versus background Gen 2 collection, foreground GCs during background GC, configuration naming, latency modes and no-GC regions.

    Senior Theory Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  19. How does finalisation work in .NET, why are finalisers expensive, and how do you diagnose a blocked finaliser thread?

    Finalisation queue and f-reachable queue, extra GC survival, the single finaliser thread, ordering and exit behaviour, SafeHandle, and debugging finaliser problems.

    Senior Debugging Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  20. How do you implement IDisposable correctly, and who is responsible for disposing an object?

    The dispose pattern, sealed simple Dispose, idempotency, ObjectDisposedException, ownership rules, DI container disposal and analyser support.

    Mid-Level Coding Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me