📁 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.

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. How does the using statement work in C#, and what are the common bugs with using declarations, deferred execution and exceptions?

    using statement versus declaration, lowering to try/finally, disposal order, pattern-based using for ref structs, and bugs with returned objects, deferred LINQ and Dispose exceptions.

    Mid-Level CodeReview Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  9. When should a type implement IAsyncDisposable, how does await using work, and how do you implement both IDisposable and IAsyncDisposable correctly?

    IAsyncDisposable and ValueTask DisposeAsync, await using lowering, ConfigureAwait on disposal, the DisposeAsyncCore pattern, and DI async scopes.

    Senior Coding Garbage Collection Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  10. What are WeakReference and ConditionalWeakTable in .NET, and when are weak references the right tool?

    Short and long weak references, WeakReference of T, ConditionalWeakTable for attached data, weak events, why weak caches are unreliable and their GC cost.

    Senior Theory Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  11. How do you investigate a memory leak in a .NET service in production, step by step?

    Confirming a leak, managed versus native growth, dotnet-counters, dotnet-gcdump comparisons, dotnet-dump and gcroot, common leak sources and verifying the fix.

    Senior Debugging Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  12. What is GC pressure in .NET, how do you measure it, and how do you reduce it (including GC.AddMemoryPressure for native memory)?

    Allocation rate and time in GC as pressure metrics, practical reduction techniques, GCConserveMemory, AddMemoryPressure for native allocations, and RefreshMemoryLimit.

    Senior Theory Garbage Collection Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  13. What is a Thread in .NET, and when would you still create one directly instead of using Task.Run or the ThreadPool?

    System.Threading.Thread: what it maps to, its cost, its API surface in .NET 10 and the narrow cases where a dedicated thread is the right choice.

    Mid-Level Theory Threads Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  14. Walk me through the lifecycle of a .NET thread. What states can it be in, and what happens on each transition?

    ThreadState values, legal transitions, Join, Sleep, Interrupt and how a thread ends, including unhandled exceptions.

    Mid-Level Theory Threads Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  15. What is the difference between a foreground thread and a background thread in .NET, and why does it matter at shutdown?

    IsBackground, which threads are background by default, process exit rules and graceful shutdown in hosted apps.

    Junior Theory Threads Β· πŸ”— 2 follow-ups
  16. How does the .NET ThreadPool work, and how does it decide how many threads to run?

    Global and local queues, work stealing, minimum threads, hill climbing, starvation injection and the metrics to watch in .NET 10.

    Senior Theory Threads Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  17. What is the difference between ThreadPool worker threads and I/O completion threads, and does it matter on Linux?

    Worker versus completion-port threads, IOCP on Windows, epoll on Linux, how async I/O completes without a thread waiting, and what GetAvailableThreads really reports.

    Senior Theory Threads Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  18. How does thread-local storage work in .NET? Compare [ThreadStatic], ThreadLocal of T and AsyncLocal of T.

    Per-thread state with ThreadStatic and ThreadLocal, why it breaks across await, and how AsyncLocal flows with ExecutionContext.

    Senior Theory Threads Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  19. What is a Task in .NET? Is a Task the same as a thread?

    Task as a promise of completion, delegate tasks versus promise tasks, TaskStatus, and the core combinators in .NET 10.

    Mid-Level Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  20. How does Task of T differ from Task, and what should you know about getting its result safely?

    `Task<T>` results, await versus .Result versus GetAwaiter().GetResult(), TaskCompletionSource of T, cached completed tasks and why `Task<T>` is not covariant.

    Mid-Level Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

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