.NET Interview Questions
Commonly asked .NET interview questions with clear, practical answers.
A curated set of .NET interview questions, from platform fundamentals through the details that come up in real technical screens.
Platform fundamentals
Q: What's the difference between .NET Framework and modern .NET? .NET Framework (up to 4.8) is the original, Windows-only platform that shipped as part of Windows itself and is now in maintenance mode — no new features, only security fixes. Modern .NET (5 and onward, the direct successor to .NET Core) is cross-platform, open-source, faster, and actively developed; every even-numbered release (6, 8, 10...) is a Long-Term Support version. All new development should target modern .NET.
Q: What are the CLR and the JIT, and how do they relate?
The CLR (Common Language Runtime) is .NET's execution engine — it loads assemblies, manages memory via garbage collection, enforces type safety, and handles exceptions. Source code compiles to CPU-independent Intermediate Language (IL); the CLR's JIT (Just-In-Time) compiler then translates that IL into native machine code for the actual CPU, method by method, the first time each is called. This two-step process is what makes the same compiled .dll runnable unchanged on Windows, macOS, or Linux.
Q: What is NuGet?
.NET's package manager — a public registry (nuget.org) of reusable libraries, plus the dotnet add/remove package CLI and the <PackageReference> element in .csproj that pins a project to specific package versions. It plays the same role npm does for Node.js or pip does for Python.
Dependency injection
Q: Explain the three built-in service lifetimes.
Singleton creates one instance for the entire application's lifetime, shared by every caller. Scoped creates one instance per scope — in ASP.NET Core, one HTTP request — shared within that request but recreated for the next. Transient creates a brand-new instance on every single resolution, even multiple times within the same scope.
Q: Why shouldn't you inject a Scoped service into a Singleton? It creates a "captive dependency" — the singleton holds onto that first scoped instance for the app's entire lifetime instead of getting a fresh one per scope, defeating the point of Scoped and often causing stale data or thread-safety issues. ASP.NET Core validates against this in Development by default and throws at startup if it detects the mismatch.
Tooling
Q: What's the difference between dotnet build, dotnet run, and dotnet publish?
dotnet build compiles the project and its dependencies into a bin/ output but doesn't run it. dotnet run builds (if needed) and immediately executes the result — the everyday development loop. dotnet publish produces a self-contained, deployable output (optionally bundling the runtime itself for a target machine that has no .NET installed), intended for actually shipping the application.
Testing and performance
Q: What's the difference between [Fact] and [Theory] in xUnit?
A [Fact] is a single, parameterless test verifying one specific behavior unconditionally. A [Theory], paired with a data source like [InlineData], runs the same test method once per supplied row of arguments — useful for confirming a rule holds across a range of inputs without writing a near-duplicate test per case.
Q: What's the purpose of a mocking library like Moq in a unit test?
It creates a lightweight fake implementation of an interface so a test can isolate the class under test from real collaborators — a database, a clock, a network call — without any of them actually running. Setup controls what the fake returns for a given call; Verify confirms a specific interaction with it actually happened, which a plain return-value assertion alone can't check.
Q: Why is .NET's garbage collector generational, and what's the practical benefit? Because most objects die young in practice, the GC frequently and cheaply collects Gen 0 (new, likely-garbage objects), promotes anything that survives up into Gen 1 and eventually Gen 2, and reserves the far more expensive whole-heap Gen 2 collection for much rarer occasions. This avoids re-scanning long-lived objects — caches, singletons, static data — on every single collection cycle.