10 role-specific questions
.NET Developer Interview Questions & Answers
.NET interviews cover C# language depth, ASP.NET Core's pipeline and dependency injection, async programming, Entity Framework Core and LINQ, and how you build maintainable, performant APIs.
Free, no sign-up. 83 questions in this role's practice pool, including behavioural, HR and situational questions.
.NET & C# interview questions
C#, ASP.NET Core, dependency injection, async/await, Entity Framework Core and LINQ.
1.
Explain dependency injection in ASP.NET Core, including service lifetimes.
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Understanding of the built-in container and lifetime bugs.
Key points a strong answer covers
- What DI is. Classes receive dependencies (often interfaces) through the constructor instead of creating them.
- Registration. Services are registered in the container in Program.cs.
- Lifetimes. Singleton: one for the app; Scoped: one per request; Transient: new each time.
- Captive dependency. A Scoped service injected into a Singleton lives too long — a captive dependency.
- Testability. DI makes it easy to swap implementations in tests.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Injecting DbContext into a singleton.
- Using the service locator pattern everywhere.
Likely follow-up questions
- How would you use a scoped service inside a BackgroundService?
- What does
ValidateScopesdo?
Example strong answer
Dependency injection means a class receives what it needs — usually as interfaces through its constructor — instead of creating it, so code is loosely coupled and easy to test with fakes. ASP.NET Core has a built-in container: you register services in
Program.cswith a lifetime. Singleton is one instance for the whole app — good for configuration or a thread-safe cache. Scoped is one per HTTP request — DbContext is the classic example. Transient creates a new instance every time it's resolved. The common bug is a captive dependency: injecting a Scoped service like DbContext into a Singleton, which keeps one DbContext alive across requests and threads. In a BackgroundService I create a scope withIServiceScopeFactoryinstead.2.
Explain middleware in ASP.NET Core and why order matters.
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Understanding the request pipeline.
Key points a strong answer covers
- Pipeline of components. Middleware components form a pipeline that each request passes through.
- next / short-circuit. Each can do work, call next(), or short-circuit the request.
- Order matters. Order defines behaviour: e.g. UseAuthentication before UseAuthorization.
- Built-in examples. Exception handling, HTTPS redirection, static files, routing, CORS, authentication, authorization.
- Custom middleware. Custom middleware for logging, correlation ids, timing.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Putting UseAuthorization before UseAuthentication.
- Registering exception handling late in the pipeline.
Likely follow-up questions
- How would you write middleware that adds a correlation id?
- What's the difference between middleware and filters?
Example strong answer
Middleware are components chained into a pipeline that every HTTP request passes through, and the response passes back out in reverse. Each component can work on the request, call
nextto pass it on, and work on the response afterwards — or short-circuit, for example returning 401 without calling next. Order matters because it's literally the order of execution: exception handling goes first so it catches everything; then HTTPS redirection, static files, routing, CORS,UseAuthenticationbeforeUseAuthorization, then endpoints. I write custom middleware as a class withInvokeAsync(HttpContext)for cross-cutting concerns like a correlation id or request timing. MVC filters are similar but run inside the endpoint, with access to model binding and action results.3.
Explain async and await in C#. What can go wrong if you call
.Resultor.Wait()?IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Correct async programming and avoiding deadlocks.
Key points a strong answer covers
- Frees the thread during I/O. await frees the thread while I/O is in progress, so the server handles more requests.
- Task represents the operation. Async methods return Task; the compiler builds a state machine that resumes after the await.
- Deadlocks / blocking. .Result/.Wait() block threads and can deadlock where there's a synchronization context.
- Async all the way. Keep code async end to end; avoid async void; ConfigureAwait(false) in libraries.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Thinking async makes code run on a new thread.
- Using async void outside event handlers.
Likely follow-up questions
- What's the difference between CPU-bound and I/O-bound async work?
- When would you use
Task.WhenAll?
Example strong answer
async/awaitlets a method wait for I/O — a database query, an HTTP call — without blocking a thread. When you await an incomplete Task, the method returns to its caller and the thread goes back to the pool; when the I/O completes, the compiler-generated state machine resumes the rest of the method. On a server that means far more concurrent requests with the same threads. It doesn't create new threads by itself. Calling.Resultor.Wait()blocks a thread while waiting, which wastes threads and, where there's a synchronization context — classic ASP.NET or UI apps — can deadlock because the continuation needs the thread you're blocking. So: async all the way, noasync voidexcept event handlers, andTask.WhenAllto run independent calls concurrently.4.
What is the difference between IEnumerable and IQueryable?
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Avoiding loading whole tables into memory with LINQ.
Key points a strong answer covers
- IEnumerable in memory. IEnumerable runs LINQ in memory using delegates.
- IQueryable builds a query. IQueryable builds an expression tree the provider translates (e.g. to SQL).
- Where filtering happens. Calling AsEnumerable/ToList too early loads all rows and filters in memory.
- Deferred execution. Both are deferred until enumerated.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Returning IEnumerable from a repository and then filtering, pulling the whole table.
- Not knowing both are deferred.
Likely follow-up questions
- What happens if you call a custom C# method inside an IQueryable Where?
- When should you call ToListAsync?
Example strong answer
Both represent sequences with deferred execution, but they run queries differently.
IEnumerable<T>works with LINQ to Objects: the operators take delegates and run in memory.IQueryable<T>builds an expression tree that a provider like Entity Framework Core translates into SQL, so aWhereandTakebecome a WHERE and a LIMIT in the database. The bug I watch for is switching to IEnumerable too early — say a repository returnsIEnumerable<Order>, or someone callsToList()first — so the whole table is loaded and filtered in memory. I keep composing on IQueryable and materialise once withToListAsync()at the end. Custom C# methods inside an IQueryable either fail to translate or, in older EF versions, silently ran client-side.5.
How does Entity Framework Core work, and how do you keep it performant?
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Practical ORM use: whether you know what EF Core does underneath and how to keep it fast.
Key points a strong answer covers
- DbContext & change tracking. DbContext tracks entities and SaveChanges writes the changes as a unit of work.
- LINQ to SQL translation. LINQ queries are translated to SQL.
- Migrations. Migrations version the schema from the model.
- Performance. AsNoTracking for reads, projections with Select, avoid N+1 with Include, check generated SQL.
- Inspect SQL. Log or inspect the generated SQL.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Loading full entities with tracking for read-only lists.
- Never looking at the generated SQL.
Likely follow-up questions
- When would you use raw SQL with EF Core?
- What does a split query solve?
Example strong answer
EF Core maps C# classes to tables. A
DbContextis a unit of work: it tracks the entities you load, andSaveChangesworks out what changed and writes the inserts, updates and deletes in a transaction. LINQ queries againstDbSets are translated to SQL, and migrations evolve the schema from the model. For performance I useAsNoTrackingfor read-only queries, project withSelectinto DTOs so only the needed columns are fetched, useIncludeto avoid N+1 lazy loading — or split queries when includes would multiply rows — and paginate. I log the generated SQL in development and check execution plans for slow queries, dropping to raw SQL or Dapper for the rare complex report.6.
What's the difference between value types and reference types in C#?
BeginnerTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Language fundamentals.
Key points a strong answer covers
- Value types hold data. Value types (structs, int, bool) hold their data and are copied on assignment.
- Reference types hold references. Reference types (classes, strings, arrays) hold a reference; copies point to the same object.
- Memory (nuanced). Value types often live inline (stack or inside objects); boxing copies them to the heap.
- string special case. string is a reference type but immutable, so it behaves like a value.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Saying value types always live on the stack.
- Forgetting boxing costs.
Likely follow-up questions
- What is boxing, and when does it happen?
- Why might you choose a record struct?
Example strong answer
A value type —
int,bool,DateTime, anystruct— holds its data directly, so assigning or passing it copies the value; changing the copy doesn't affect the original. A reference type — classes, arrays,string— holds a reference to an object on the heap, so two variables can point to the same object and see each other's changes. People often say value types always go on the stack, but they actually live wherever they're declared — inside an object they're on the heap. Converting a value type toobjector an interface boxes it, allocating a heap copy, which matters in hot loops.stringis a reference type but immutable, so it behaves like a value.7.
What is LINQ, and what is deferred execution?
BeginnerTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Everyday C# fluency, and whether you know when a query actually runs.
Key points a strong answer covers
- Query syntax over collections. LINQ is a uniform query syntax over collections and data sources.
- Deferred execution. Most operators don't run until the result is enumerated.
- Materialise. ToList, Count or First execute immediately.
- Multiple enumeration. Enumerating a deferred query twice runs it twice.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Enumerating an expensive query several times.
- Not knowing when the query actually runs.
Likely follow-up questions
- Why can multiple enumeration be a bug with IQueryable?
- Method syntax or query syntax — which do you prefer?
Example strong answer
LINQ — Language Integrated Query — gives a uniform way to filter, project, sort and group data with methods like
Where,Select,OrderByandGroupBy, whether it's an in-memory list or a database through EF Core. Most operators use deferred execution:orders.Where(o => o.Total > 100)doesn't run anything yet; it runs when you enumerate it withforeach, or callToList,CountorFirst, which execute immediately. That's efficient, but if you enumerate the same query twice it runs twice — against a database that's two round-trips, and the results can differ — so I materialise withToListwhen I need the results more than once.8.
When would you use a record, a class or a struct in C#?
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Modern C# design choices.
Key points a strong answer covers
- Records: value equality. Records give value-based equality, concise syntax and
withcopies — ideal for DTOs and immutable data. - Classes: identity & behaviour. Classes for entities and services with identity and behaviour.
- Structs: small values. Structs for small, short-lived values to avoid allocations.
- Trade-offs. Large or mutable structs are a trap; copies get expensive.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Using mutable structs.
- Using records for EF entities that rely on reference identity.
Likely follow-up questions
- What does the
withexpression do? - Why are mutable structs dangerous?
Example strong answer
I use a
recordfor data whose identity is its values — DTOs, API request and response models, value objects like Money — because records give value-based equality, a readableToString, concise positional syntax and non-destructive copies withwith. Aclassis for things with identity and behaviour that may change over time: domain entities, services, EF Core entities that rely on reference identity and change tracking. Astructis for small, immutable values used in large numbers or hot paths — a coordinate, a small key — where avoiding heap allocations matters; I keep them small and read-only, because large or mutable structs are copied silently and cause bugs.- Records: value equality. Records give value-based equality, concise syntax and
9.
How does garbage collection work in .NET, and how do you avoid memory problems?
AdvancedTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Runtime knowledge for performance work.
Key points a strong answer covers
- Generations. The GC is generational: most objects die young in Gen 0; survivors are promoted.
- Large object heap. Objects over ~85 KB go on the Large Object Heap, collected less often.
- IDisposable. Unmanaged resources need Dispose / using — the GC only handles memory.
- Reduce allocations / leaks. Reduce allocations (Span, pooling) and avoid leaks from static caches and event handlers.
- Diagnose. Diagnose with dotnet-counters, dumps and memory profilers.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Calling GC.Collect() to fix memory issues.
- Confusing Dispose with garbage collection.
Likely follow-up questions
- What's the difference between Dispose and a finalizer?
- How can an event subscription cause a leak?
Example strong answer
The .NET GC is generational. New objects go in Gen 0, which is collected often and cheaply because most objects die young; survivors are promoted to Gen 1 and then Gen 2, collected less often. Objects over about 85 KB go to the Large Object Heap. The GC only manages memory, so files, sockets and database connections implement
IDisposableand I release them withusing. To avoid problems I reduce allocations in hot paths —Span<T>,ArrayPool, avoiding needless LINQ in tight loops — and watch for leaks such as static caches that only grow or event handlers that keep subscribers alive. I diagnose withdotnet-counters, memory dumps and a profiler rather than callingGC.Collect().10.
Minimal APIs or controllers in ASP.NET Core — how do you choose, and how do you structure an API?
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
API project organisation.
Key points a strong answer covers
- Minimal APIs. Minimal APIs map endpoints with lambdas — lightweight and fast to write.
- Controllers. Controllers group actions in classes with attribute routing and filters.
- Structure. Organise by feature, keep business logic out of endpoints.
- Cross-cutting. Validation, ProblemDetails errors, OpenAPI and auth applied consistently.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Putting business logic inside endpoints or controllers.
- Treating the choice as a performance decision only.
Likely follow-up questions
- How do endpoint filters compare with MVC filters?
- How would you return consistent error responses?
Example strong answer
Both are fine in modern .NET. Minimal APIs map endpoints directly with
MapGetandMapPost, are concise and slightly faster to start, and withMapGroupand endpoint filters they scale to real APIs — I like them for services organised by feature. Controllers bundle related actions in classes with attribute routing, model binding conventions and MVC filters, which a lot of teams and existing code already know. Whichever I use, the endpoint stays thin: it validates input — FluentValidation or data annotations — calls a service or handler where the business logic lives, and returns typed results. Errors use ProblemDetails consistently, and OpenAPI documentation is generated from the endpoints.
Ready to answer them out loud?
Run a timed .net developer mock interview, type or speak your answers, and get a score breakdown with what to improve.