.NET interview questions and answers
Most .NET interviews spend more time on async/await, dependency injection and EF Core behaviour than on syntax trivia, because those are the areas where a wrong mental model causes real production bugs.
These answers are current to the unified .NET (post .NET 5) line and C# 12 — record types, primary constructors, minimal APIs and Native AOT are all in here alongside the fundamentals.
Runtime and platform
- .NET Framework vs .NET (Core)?
- .NET Framework is the legacy Windows-only runtime, now in maintenance mode. .NET, formerly .NET Core and now versioned as .NET 8/9, is the cross-platform runtime that unified Framework, Core and Xamarin from .NET 5 onward.
- What does Native AOT in .NET 8 trade off?
- It compiles the app to native code at publish time, cutting startup time and memory for CLI tools and small services. The trade-off is losing full reflection-based features unless libraries are written to be AOT-compatible.
Async and concurrency
- Task vs Task<T>?
- Task represents an asynchronous operation with no return value, like an awaitable void. Task<T> represents one that eventually produces a value of type T. Both carry completion state and any exception.
- Why avoid .Result or .Wait() in async code?
- They block the calling thread until the task completes, and in a context with a captured SynchronizationContext this can deadlock if the awaited task needs that same thread to continue. Awaiting instead yields the thread back.
- What does ConfigureAwait(false) do?
- It tells the awaiter not to resume on the original synchronization context, avoiding a deadlock risk and a context-switch cost. ASP.NET Core has no SynchronizationContext by default, so it mainly matters in library code that might run under WinForms or WPF.
- Task.Run vs calling an async method directly?
- Task.Run queues work onto the thread pool, appropriate for offloading CPU-bound work off a UI thread. An async I/O call like HttpClient.GetAsync does not need Task.Run — it is already non-blocking, since the OS handles the wait.
- What is the CancellationToken pattern for?
- It lets a caller signal that a long-running or async operation should stop, propagated through nested calls so each can check IsCancellationRequested, rather than the caller forcibly killing a thread.
- IEnumerable<T> vs IAsyncEnumerable<T>?
- IEnumerable<T> is iterated synchronously with MoveNext(). IAsyncEnumerable<T> is iterated with await foreach, letting each element be produced asynchronously without blocking the thread while it waits.
Dependency injection and ASP.NET Core
- What are the three DI lifetimes in ASP.NET Core?
- Transient creates a new instance on every request for it. Scoped creates one instance per HTTP request. Singleton creates one instance for the app’s lifetime.
- Why can a Singleton not depend directly on a Scoped service?
- The Scoped instance would be captured once and live for the app’s lifetime instead of per-request. ASP.NET Core’s DI container validates this at startup by default and throws.
- Minimal APIs vs MVC controllers?
- Minimal APIs map routes directly to lambda or method handlers without a controller class, reducing boilerplate for small services. Controllers still offer more structure — filters, model binding conventions, versioning — for larger APIs.
- IOptions<T> vs raw configuration reads?
- IOptions<T>, and its siblings IOptionsSnapshot and IOptionsMonitor, bind a strongly typed class to a configuration section so you inject a POCO instead of reading raw config strings scattered through the code.
C# language features
- record vs class in C#?
- A record has value-based equality — two records with the same property values are equal — and supports concise with-expressions for non-destructive copies. A class has reference equality by default.
- What do nullable reference types solve?
- With <Nullable> enabled, the compiler warns when a reference type not annotated with ? is assigned null or dereferenced without a check, catching a large class of null-reference bugs at compile time.
- What do primary constructors (C# 12) change?
- A class or struct can declare constructor parameters in its header, and those parameters stay in scope through the class body without manual field assignment, cutting constructor boilerplate for simple cases.
- What can a pattern-matching switch expression do that a switch statement could not easily?
- It matches on type, property and relational patterns in one expression that returns a value directly, e.g. result switch { > 0 => "positive", 0 => "zero", _ => "negative" }, instead of a statement with break and an out variable.
- What does the using declaration guarantee?
- It calls Dispose() on an IDisposable when the enclosing scope ends, even if an exception is thrown, compiling to a try/finally. The C# 8 using declaration disposes at the end of the containing block without needing braces.
Entity Framework Core and background work
- IEnumerable vs IQueryable?
- IEnumerable executes in memory once you start iterating. IQueryable builds an expression tree a provider like EF Core translates into SQL, and only executes on enumeration — filtering on an IQueryable pushes the WHERE clause to the database.
- What does .AsNoTracking() change in EF Core?
- EF Core normally tracks each entity’s original and current values so SaveChanges() knows what to update. AsNoTracking() skips that bookkeeping for read-only queries, which is noticeably faster since there is nothing to diff.
- IHostedService vs BackgroundService?
- IHostedService is the raw interface with StartAsync and StopAsync you implement directly. BackgroundService is an abstract base class that implements it for you, so most background workers just override ExecuteAsync with a loop.
How this is worked out
- Twenty questions grouped by runtime, async, DI, language features and EF Core.
- Everything reflects the unified .NET line (5 and later) and C# 12, with .NET Framework called out only where it differs.
- Answers explain the mechanism a follow-up would probe, not just the one-line rule.
What this does not cover
- This assumes basic C# familiarity — it is not a first tutorial on the language.
- ASP.NET MVC view-engine specifics and WPF/WinForms are out of scope; this page is API and service-focused .NET.
- Version-specific API surface (attribute names, package names) can shift between .NET releases — verify against the target project’s actual SDK version before an interview.
Questions people ask
- Do I need to know old .NET Framework for a modern .NET role?
- Only if the job posting or the codebase you would join is on Framework. Most new roles are on .NET 8 or 9, where the cross-platform, unified runtime is the default assumption.
- What is the single most-asked question here?
- Why calling .Result or .Wait() on a task can deadlock. It is a real production bug people have hit, which makes it a durable interview question.
- Is Native AOT commonly asked about?
- It comes up more as an awareness check — knowing it exists and its trade-off — than as a deep-dive topic, unless the role specifically builds CLI tools or high-density services.
Where these figures come from
Rates and rules on this page were last checked against the source on . Tax law changes; check the source before you rely on a number for a decision.
Related calculators
Running these numbers because you are weighing a move? See what is open right now.