Skip to content
Resume Studioby M2Toolkit

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. 1.

    Explain dependency injection in ASP.NET Core, including service lifetimes.

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 ValidateScopes do?
    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.cs with 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 with IServiceScopeFactory instead.

    Practise this question and get feedback
  2. 2.

    Explain middleware in ASP.NET Core and why order matters.

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 next to 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, UseAuthentication before UseAuthorization, then endpoints. I write custom middleware as a class with InvokeAsync(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.

    Practise this question and get feedback
  3. 3.

    Explain async and await in C#. What can go wrong if you call .Result or .Wait()?

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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/await lets 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 .Result or .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, no async void except event handlers, and Task.WhenAll to run independent calls concurrently.

    Practise this question and get feedback
  4. 4.

    What is the difference between IEnumerable and IQueryable?

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 a Where and Take become a WHERE and a LIMIT in the database. The bug I watch for is switching to IEnumerable too early — say a repository returns IEnumerable<Order>, or someone calls ToList() first — so the whole table is loaded and filtered in memory. I keep composing on IQueryable and materialise once with ToListAsync() at the end. Custom C# methods inside an IQueryable either fail to translate or, in older EF versions, silently ran client-side.

    Practise this question and get feedback
  5. 5.

    How does Entity Framework Core work, and how do you keep it performant?

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 DbContext is a unit of work: it tracks the entities you load, and SaveChanges works out what changed and writes the inserts, updates and deletes in a transaction. LINQ queries against DbSets are translated to SQL, and migrations evolve the schema from the model. For performance I use AsNoTracking for read-only queries, project with Select into DTOs so only the needed columns are fetched, use Include to 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.

    Practise this question and get feedback
  6. 6.

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

    BeginnerTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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, any struct — 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 to object or an interface boxes it, allocating a heap copy, which matters in hot loops. string is a reference type but immutable, so it behaves like a value.

    Practise this question and get feedback
  7. 7.

    What is LINQ, and what is deferred execution?

    BeginnerTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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, OrderBy and GroupBy, 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 with foreach, or call ToList, Count or First, 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 with ToList when I need the results more than once.

    Practise this question and get feedback
  8. 8.

    When would you use a record, a class or a struct in C#?

    IntermediateTechnical

    What 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 with copies — 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 with expression do?
    • Why are mutable structs dangerous?
    Example strong answer

    I use a record for data whose identity is its values — DTOs, API request and response models, value objects like Money — because records give value-based equality, a readable ToString, concise positional syntax and non-destructive copies with with. A class is 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. A struct is 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.

    Practise this question and get feedback
  9. 9.

    How does garbage collection work in .NET, and how do you avoid memory problems?

    AdvancedTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 IDisposable and I release them with using. 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 with dotnet-counters, memory dumps and a profiler rather than calling GC.Collect().

    Practise this question and get feedback
  10. 10.

    Minimal APIs or controllers in ASP.NET Core — how do you choose, and how do you structure an API?

    IntermediateTechnical

    What 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

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. 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 MapGet and MapPost, are concise and slightly faster to start, and with MapGroup and 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.

    Practise this question and get feedback

Behavioural & HR questions you'll also get

These come up in almost every .net developer interview. Story questions are best answered with STAR — Situation, Task, Action, Result.

  • Tell me about yourself.

    BeginnerHR

    What the interviewer is evaluating

    Whether you can give a concise, relevant pitch that frames your experience around this job.

    Key points a strong answer covers

    • Present. Start with your current role and what you do.
    • Relevant past. Pick the most relevant past experience.
    • Strength / achievement. Include one strength or achievement with evidence.
    • Why this role. Finish with why this role is the next step.

    Suggested answer structure

    1. Present — your current role in one or two sentences.
    2. Past — the experience most relevant to this job.
    3. Proof — one achievement or strength with evidence.
    4. Future — why this role is the logical next step.

    Common mistakes

    • Reciting your whole CV chronologically.
    • Personal life story unrelated to the job.
    • Going over two minutes.

    Likely follow-up questions

    • Why are you looking to leave your current role?
    • What would your manager say is your biggest strength?
    Example strong answer

    I'm a front-end developer with four years' experience, currently at a fintech start-up where I build the customer dashboard in React and TypeScript. Before that I spent two years at an agency building e-commerce sites, which taught me to work fast with lots of different clients. The thing I'm proudest of recently is leading our move to a shared component library, which cut the time to build new screens by about a third. I'm now looking for a role where I can work on a larger product with a strong design system, which is exactly what drew me to this position.

  • Why should we hire you?

    BeginnerHR

    What the interviewer is evaluating

    Whether you understand the role and can match your strengths to its needs with evidence.

    Key points a strong answer covers

    • Role's needs. Show you understand what the role needs.
    • Matching strengths. Match two or three strengths to those needs.
    • Evidence. Back each with evidence.
    • Enthusiasm. Close with genuine enthusiasm.

    Suggested answer structure

    1. Name the two or three things the role needs most.
    2. Match each with your experience and evidence.
    3. Add what makes you different.
    4. Finish with genuine interest.

    Common mistakes

    • Generic claims like 'I'm hardworking' with no evidence.
    • Comparing yourself to other candidates you don't know.

    Likely follow-up questions

    • What would you do in your first 90 days?
    • What's one area where you'd need support?
    Example strong answer

    From the job description and our conversation, you need someone who can take ownership of the customer onboarding process, work with sales and product, and improve the numbers. I've done exactly that for three years: at my current company I redesigned onboarding for new accounts and cut the time to first value from 14 days to 6. I'm comfortable working across teams — I run a weekly session with sales and product on customer feedback — and I'm very data-driven, so I'd measure everything from day one. I'm also genuinely excited about your product, because it solves a problem I've seen customers struggle with.

  • Tell me about a time you disagreed with a teammate. How did you handle it?

    BeginnerBehavioural

    What the interviewer is evaluating

    Handling conflict constructively and keeping relationships.

    Key points a strong answer covers

    • Listened to their view. Show you listened to understand their view.
    • Used facts / common goal. Bring it back to facts or a shared goal.
    • Resolution & relationship. Resolve it and keep the relationship.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Making the other person the villain.
    • A story where you were simply right and they gave in.

    Likely follow-up questions

    • What if you couldn't reach agreement?
    • Have you ever been wrong in a disagreement?
    Example strong answer (a fictional story — use your own)

    On a website rebuild, a senior designer wanted an animated, image-heavy homepage, and I was worried it would hurt mobile load times and SEO. As the developer responsible for performance, I needed us to agree before the sprint started. I asked her to walk me through what she was trying to achieve — she wanted the brand to feel premium. I built two quick prototypes, one with her full design and one with lighter animations, and we tested both on a mid-range phone together. Hers took nearly six seconds to load. We agreed on a version that kept the key animation but lazy-loaded the rest. The page launched loading in under two seconds, and she later asked me to review designs earlier. I learned that testing together beats debating.

  • Tell me about a mistake you made and what you learned.

    BeginnerBehavioural

    What the interviewer is evaluating

    Honesty, accountability and learning.

    Key points a strong answer covers

    • Real mistake owned. Own a real mistake.
    • Fixed it. Show how you fixed it and who you told.
    • Changed behaviour. Show what you changed afterwards.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Choosing a fake mistake like 'I work too hard'.
    • Blaming others.

    Likely follow-up questions

    • How did your manager react?
    • How do you know you haven't repeated it?
    Example strong answer (a fictional story — use your own)

    In my first year as a marketing coordinator, I sent a promotional email to our whole list with the wrong discount code — I'd tested the email but not clicked the code itself. Within an hour customers were complaining that it didn't work. I told my manager immediately, set the wrong code to apply the discount too, and sent a short correction email with an apology. We lost very little revenue, and some customers replied thanking us for the quick fix. Since then I use a pre-send checklist that includes testing every link and code as a customer would, and I asked for a second person to check any campaign to more than 10,000 people.

  • Describe a situation where you worked under pressure or to a tight deadline.

    BeginnerBehavioural

    What the interviewer is evaluating

    Prioritisation, composure and delivery.

    Key points a strong answer covers

    • The pressure. Make the pressure concrete.
    • Prioritised. Show how you prioritised.
    • Communicated. Show how you kept people informed.
    • Delivered. Show the outcome.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Glorifying working all night as the solution.
    • No mention of prioritising.

    Likely follow-up questions

    • What would you do if it was clear you couldn't make the deadline?
    • How do you stop pressure affecting quality?
    Example strong answer (a fictional story — use your own)

    Two days before a client presentation, our analyst fell ill and I had to finish the market research report she'd been leading. I listed everything left and asked the account director which sections the client cared about most — pricing and competitor comparison. I focused on those, reused verified data from our previous report, and moved the appendix to a follow-up email. I sent a short update each evening so nobody was surprised. We delivered the core report on time, the client approved the next phase, and the appendix followed two days later. I learned to ask early what matters most rather than trying to do everything equally well.

  • What would you do if you realised you were going to miss a deadline?

    BeginnerSituational

    What the interviewer is evaluating

    Transparency and problem solving.

    Key points a strong answer covers

    • Tell people early. Flag it as soon as you know.
    • Assess the gap. Work out how far off you are.
    • Options. Offer options: reduced scope, help, a new date.
    • Prevent repeats. Learn why it happened.

    Suggested answer structure

    1. Clarify the situation and what's at stake.
    2. Say what you'd do first, and why.
    3. Explain who you'd involve and how you'd communicate.
    4. Describe how you'd check the outcome and prevent a repeat.

    Common mistakes

    • Waiting until the deadline to say anything.
    • Promising you'll just work all night.

    Likely follow-up questions

    • What if your manager is unavailable?
    • Has this happened to you?
    Example strong answer

    I'd tell the person depending on it as soon as I realised, not at the deadline. Before that conversation I'd work out how far off I am and why, so I could offer options: delivering the most important part on time and the rest a few days later, getting help from a colleague, or agreeing a new date. Then I'd let them decide what works best for them, and keep them updated. Afterwards I'd look at why it slipped — usually underestimating something — so I plan better next time.

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.

Interview questions for related roles