📁 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 ValueTask, when should you use it instead of Task, and what rules must callers follow?

    ValueTask and `ValueTask<T>`: allocation-free synchronous completion, IValueTaskSource pooling, consumption rules and when Task is still the better choice.

    Senior Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  2. What do the async and await keywords actually do? Explain what happens when execution reaches an await.

    The async modifier, the awaitable pattern, the IsCompleted fast path, continuation registration, context capture and valid async return types.

    Mid-Level Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  3. What does the compiler generate for an async method? Explain the async state machine.

    IAsyncStateMachine, MoveNext, the state field, hoisted locals, the method builder, boxing on first suspension and the cost model of async in .NET 10.

    Senior Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  4. What is a TaskScheduler, and what is the difference between TaskScheduler.Default and TaskScheduler.Current?

    TaskScheduler responsibilities, the default ThreadPool scheduler, Current versus Default pitfalls with StartNew and ContinueWith, FromCurrentSynchronizationContext and ConcurrentExclusiveSchedulerPair.

    Senior Theory Tasks Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  5. What are task continuations? Compare ContinueWith with await and explain the options that control how continuations run.

    ContinueWith, TaskContinuationOptions, synchronous versus asynchronous continuations, RunContinuationsAsynchronously, Unwrap and why await is usually better.

    Senior Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  6. How are exceptions handled in tasks and async methods? What happens with Task.WhenAll, unobserved exceptions and async void?

    Exceptions stored in tasks, AggregateException versus await, WhenAll with several failures, cancellation status, UnobservedTaskException and async void crashes.

    Senior Debugging Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  7. What are the risks of fire-and-forget tasks in .NET, and how would you run background work safely in ASP.NET Core?

    Lost exceptions, disposed scoped services, lost work on shutdown, no backpressure; safe alternatives with BackgroundService, Channel of T and durable queues.

    Senior RealWorldScenario Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  8. How does the lock statement work in C#, and what changed with System.Threading.Lock in .NET 9 and C# 13?

    lock lowering to Monitor or Lock.EnterScope, choosing the lock object, re-entrancy, why you cannot await inside a lock, and lock scope design.

    Mid-Level Theory Synchronization Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  9. What does the Monitor class provide beyond the lock statement? Explain TryEnter, Wait and Pulse.

    Monitor.Enter/Exit, TryEnter with timeouts, Wait/Pulse/PulseAll condition signalling, thread affinity and the object header thin lock and sync block.

    Senior Theory Synchronization Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  10. What is a Mutex in .NET, how is it different from lock, and when would you use a named Mutex?

    Kernel mutex, cross-process named mutexes, Global and Local prefixes, AbandonedMutexException, thread affinity, cost and single-instance apps.

    Mid-Level Theory Synchronization Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  11. What is a Semaphore in .NET, and how does it differ from a Mutex?

    Counting semaphores, System.Threading.Semaphore as a kernel object, named semaphores and platform limits, no thread affinity, SemaphoreFullException and use cases.

    Mid-Level Theory Synchronization Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  12. What is SemaphoreSlim, and how do you use it as an async lock or to throttle concurrent async work?

    SemaphoreSlim internals, WaitAsync with timeouts and cancellation, async mutual exclusion, throttling HTTP calls, non-reentrancy and release discipline.

    Mid-Level Coding Synchronization Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  13. What is SpinLock, and when (if ever) should you use it instead of lock?

    SpinLock and SpinWait, busy-waiting versus blocking, struct copying pitfalls, owner tracking and why most code should not use it.

    Senior Theory Synchronization Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  14. When would you use ReaderWriterLockSlim, and what are its pitfalls compared with lock or immutable snapshots?

    Read, write and upgradeable read locks, recursion policy, thread affinity, performance reality and lock-free alternatives for read-mostly data.

    Senior Theory Synchronization Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  15. What does the Interlocked class do, and how do you build a lock-free update with CompareExchange?

    Atomic Increment, Add, Exchange, CompareExchange, Read, And and Or; full fences; CAS loops; ABA and when lock-free is worth it.

    Senior Coding Synchronization Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  16. What does volatile mean in C#, and how do Volatile.Read and Volatile.Write differ from Interlocked?

    Compiler and CPU reordering, acquire and release semantics, the volatile keyword, Volatile class, x64 versus Arm64 memory models and what volatile does not guarantee.

    Senior Theory Synchronization Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  17. What are memory barriers, why do CPUs and compilers reorder memory operations, and how does .NET expose barriers?

    Store buffers and reordering, full versus half fences, Interlocked.MemoryBarrier, implicit barriers in locks and Interlocked, double-checked locking and MemoryBarrierProcessWide.

    Staff / Architect Theory Synchronization Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  18. What is a SynchronizationContext, which .NET app models have one, and how does it cause the classic async deadlock?

    SynchronizationContext Post and Send, UI and legacy ASP.NET contexts, ASP.NET Core having none, and the blocking-on-async deadlock.

    Senior Debugging Async Advanced Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  19. What does ConfigureAwait(false) do, when should you use it, and what are ConfigureAwaitOptions in .NET 8+?

    Context capture, library versus application code, the already-completed caveat, ASP.NET Core relevance, CA2007 and ConfigureAwaitOptions.

    Mid-Level Theory Async Advanced Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  20. How does cooperative cancellation with CancellationToken work in .NET, and how do you design APIs that support it?

    CancellationTokenSource and token, ThrowIfCancellationRequested, Register, OperationCanceledException, RequestAborted in ASP.NET Core, disposal and where not to cancel.

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

🌐 Sangam's Webring

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