P
prepair.app
Start interview →
EnglishУкраїнськаРусскийDeutsch
🟣

.NET interview questions

.NET interviews move between C# the language and the runtime underneath it — the CLR, the GC, how async/await actually works — before landing on ASP.NET Core and Entity Framework Core, where most real-world questions live. Below are the questions asked most often, each with a model answer.

Junior · no experience / under 1 yearMiddle · 2–4 years of experienceSenior · 5+ years of experience

What they ask about

C# types, LINQ and nullable reference types
Async/await and the Task-based model
CLR, JIT and garbage collection
ASP.NET Core: middleware and dependency injection
Entity Framework Core and query performance
Testing with xUnit/Moq, Docker and cloud deployment

9 real questions with answers

Every question comes with a model answer you can compare yours against.

1

What is the difference between value types and reference types in C#?

Answer

A value type (struct, int, bool, enum) holds its data directly and gets copied on assignment; a reference type (class, string, arrays) holds a pointer to data on the heap, and assignment copies the pointer, not the object. Passing a struct into a method that mutates it silently operates on a copy unless you pass it by ref. A struct stored in a field of a class lives on the heap right there with it, not on the stack.

2

What is boxing and unboxing, and why does it matter for performance?

Answer

Boxing wraps a value type in an object on the heap so it can be treated as object — passing an int where object is expected, or into a non-generic ArrayList. Unboxing casts it back and copies the value out. Each box is a heap allocation and a GC candidate, so a loop boxing millions of ints generates real collection pressure that generics avoid entirely.

3

What problem do nullable reference types solve?

Answer

Before C# 8, string name and a value that could be null looked identical, so the compiler could not warn you that a method returning null was about to blow up three calls later. With nullable reference types enabled, string means "never null" and string? means "can be null", and the compiler warns when you dereference a ? type without a check. It adds no runtime enforcement, but it turns most null-reference bugs into compile-time warnings instead of a 2 a.m. NullReferenceException.

4

What does it mean that LINQ query execution is deferred?

Answer

var query = users.Where(u => u.Active) does not touch the data — it builds a pipeline that runs when you enumerate it with foreach, .ToList(), .Count(), or similar. That is why the same query variable can return different results if the underlying collection changes between building it and enumerating it, and why calling .ToList() too early defeats further filtering while calling it too late means an IQueryable re-runs against the database on every enumeration.

5

What actually happens when you `await` a `Task`?

Answer

The compiler rewrites the method into a state machine: code up to the await runs synchronously, and if the awaited task is not yet complete, the method returns control to its caller immediately, freeing the thread. When the task completes, the continuation resumes — by default on the captured SynchronizationContext in UI apps, which is why ConfigureAwait(false) in library code avoids deadlocks. async does not mean "runs on another thread"; it means "does not block the thread while waiting".

6

What are GC generations and why does the runtime use them?

Answer

The CLR groups objects into generation 0, 1 and 2 on the observation that most objects die young — a request-scoped DTO is garbage within milliseconds, a cached config object survives for the app lifetime. Gen 0 collections are cheap and frequent; a survivor is promoted to gen 1, then gen 2, and gen 2 collections scan the whole live heap and are expensive. Objects of 85,000 bytes or more skip straight to the Large Object Heap, which is collected with gen 2 and does not compact by default.

7

Walk through the ASP.NET Core middleware pipeline.

Answer

Each request passes through middleware registered in Program.cs in the order added — typically exception handling, HTTPS redirection, routing, authentication, authorization, then the endpoint. Every middleware can act before calling next(), after, or both, and can short-circuit by not calling next() at all, which is how authentication rejects a request before it reaches your controller. Order is not cosmetic — authorization before routing means there is no matched endpoint yet to check policies against, and it throws.

8

When does Entity Framework Core cause an N+1 problem, and how do you fix it?

Answer

Loading a list of orders, then accessing order.Customer.Name inside a foreach without eager loading fires one query per order — the same N+1 pattern as any ORM. Include(o => o.Customer) fixes it with a JOIN, or AsSplitQuery() when a join would multiply rows across several included collections. Change tracking is a related cost: EF Core snapshots every tracked entity to detect changes on SaveChanges(), which is wasted work for a read-only list, so read paths should use AsNoTracking().

9

What is the difference between the built-in DI lifetimes — Transient, Scoped and Singleton?

Answer

Transient creates a new instance every time it is requested. Scoped creates one instance per request and reuses it for the rest of that request. Singleton creates one instance for the life of the application. The classic bug is injecting a scoped service — like a DbContext — into a singleton: it captures the first request's scoped instance and holds it forever, which either throws on later use or silently shares state across unrelated requests.

🦎

Reading answers is not enough

In a real interview you speak under pressure. Cam asks these same questions, scores every answer, and shows exactly what to fix.

Practice a .NET Backend Developer interview →
Free · 3 interviews per month

Worth reading

All articles →

Other specializations

🔍Manual QA🤖QA AutomationJava Backend🐍Python Backend🐘PHP Backend🦫Go Backend🟢Node.js Backend💎Ruby on Rails🔷C++🟨JavaScript⚛️React Frontend💚Vue Frontend🅰️Angular FrontendNext.js🍏iOS (Swift)🟩Android (Kotlin)📱React Native Developer⚙️DevOps / SRE🗄️Data Engineer🧠AI/ML Engineer📊Data Scientist📈Business Analyst🎯Product Manager📋Project Manager🎨UI/UX Designer📣Marketing🧑‍💼HR / Recruiter🤝Sales / Account Manager🎧Technical Support Engineer