November 22, 2025
9 min read

C#/.NET Backend Developer Interview Questions and Answers

interview
career-advice
job-search
C#/.NET Backend Developer Interview Questions and Answers
Milad Bonakdar

Milad Bonakdar

Author

Prepare for C#/.NET backend interviews with practical questions on ASP.NET Core, EF Core, async code, DI, REST APIs, testing, and architecture.


Introduction

For a C#/.NET backend developer interview, be ready to explain how you build APIs with ASP.NET Core, keep database access efficient with EF Core, use async code without blocking threads, and structure services with dependency injection. Strong answers connect the concept to a real backend tradeoff: performance, reliability, testability, or maintainability.

Use this guide as a practical checklist. Review the short answers, then practice turning each one into a concrete example from a project, internship, coding exercise, or production bug you helped solve.


C# Language Fundamentals

1. What is the difference between struct and class in C#?

Answer:

  • Class: A reference type (allocated on the heap). When you pass a class object to a method, you are passing a reference to the memory location. Changes inside the method affect the original object. Supports inheritance.
  • Struct: A value type (allocated on the stack). When you pass a struct, a copy of the data is passed. Changes inside the method do not affect the original struct. Does not support inheritance (but can implement interfaces).
  • Usage: Use struct for small, immutable data structures representing a single value (like Point, Color). Use class for most other objects.

Rarity: Common Difficulty: Easy


2. Explain async and await. How does it help with scalability?

Answer: async and await let a method pause while an I/O operation is in progress and resume when the Task completes.

  • Mechanism: await does not create a new thread. For database, file, or network calls, it frees the request thread so the server can handle other work while the operation is pending.
  • Scalability: In ASP.NET Core, this helps throughput for I/O-bound endpoints because blocked thread-pool threads are avoided. It does not make CPU-heavy work faster; for CPU-bound work, you need better algorithms, background processing, or more compute.
  • Interview tip: Mention CancellationToken, ConfigureAwait only when relevant, and EF Core async methods such as ToListAsync or SaveChangesAsync for database I/O.

Rarity: Very Common Difficulty: Medium


3. What is Dependency Injection (DI) and how is it implemented in .NET?

Answer: Dependency Injection is a pattern where a class receives the services it needs instead of constructing them directly.

  • In .NET: ASP.NET Core includes a built-in service container. You register services in Program.cs and usually inject them through constructors or endpoint parameters.
  • Lifetimes:
    • Transient: Created each time they are requested. Good for lightweight, stateless services.
    • Scoped: Created once per request. Common for EF Core DbContext.
    • Singleton: Shared for the app lifetime. Use only when the service is thread-safe and does not capture scoped services.

Rarity: Very Common Difficulty: Medium


4. What is the difference between IEnumerable<T> and IQueryable<T>?

Answer:

  • IEnumerable<T>: Executes the query in memory. If used with a database (EF Core), it fetches all data from the server to the client memory and then filters it. Good for LINQ to Objects.
  • IQueryable<T>: Executes the query remotely (e.g., on the SQL server). It builds an expression tree that is translated into a SQL query. Filtering happens on the database side, which is much more efficient for large datasets.

Rarity: Common Difficulty: Medium


5. What are Extension Methods?

Answer: Extension methods allow you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.

  • Syntax: Defined as static methods in a static class. The first parameter specifies which type the method operates on, preceded by the this keyword.
  • Example: Adding a WordCount() method to the string class.

Rarity: Common Difficulty: Easy


ASP.NET Core & Architecture

6. What is Middleware in ASP.NET Core?

Answer: Middleware are software components that are assembled into an application pipeline to handle requests and responses.

  • Pipeline: Each component chooses whether to pass the request to the next component in the pipeline and can perform work before and after the next component is invoked.
  • Examples: Authentication, Authorization, Logging, Exception Handling, Static Files serving.
  • Order Matters: The order in which middleware is added in Program.cs defines the order of execution.

Rarity: Very Common Difficulty: Medium


7. Explain the difference between .NET Core and .NET Framework.

Answer:

  • .NET Framework: The original, Windows-only implementation. Mature, but tied to Windows.
  • .NET Core / modern .NET: The cross-platform, open-source successor line. Since .NET 5, the platform is generally called .NET; current releases include .NET 10 as an LTS release with C# 14 support.
  • Key Differences: Modern .NET is the default choice for new backend APIs because it supports Linux containers, side-by-side versions, modern ASP.NET Core features, and active performance/runtime improvements.

Rarity: Common Difficulty: Easy


8. What is Kestrel?

Answer: Kestrel is a cross-platform, open-source, event-driven web server that is included by default in ASP.NET Core templates.

  • Role: It listens for HTTP requests and passes them to the application.
  • Usage: It can run standalone (edge server) or behind a reverse proxy like IIS, Nginx, or Apache. Using a reverse proxy is recommended for production to handle security, load balancing, and SSL termination.

Rarity: Medium Difficulty: Medium


9. How do you handle Global Exception Handling in ASP.NET Core?

Answer: Instead of repeating try/catch blocks in every controller or endpoint, handle unexpected errors once at the edge of the request pipeline.

  • UseExceptionHandler: Catches unhandled exceptions, logs them, and routes the request to a configured handler.
  • Problem Details: For APIs, return a consistent ProblemDetails response without leaking stack traces or internal exception messages.
  • Expected errors: Validation failures, missing resources, and authorization failures should usually be modeled explicitly rather than thrown as generic exceptions.

Rarity: Common Difficulty: Medium


Database & Entity Framework

10. What is Entity Framework Core (EF Core)? Code-First vs. Database-First?

Answer: EF Core is an Object-Relational Mapper (ORM) for .NET. It enables developers to work with a database using .NET objects.

  • Code-First: You define your domain classes (entities) first, and EF Core creates/updates the database schema based on them using Migrations. Preferred for new projects.
  • Database-First: You have an existing database, and EF Core generates the .NET classes (scaffolding) based on the schema.

Rarity: Common Difficulty: Easy


11. What is the N+1 problem in EF Core and how do you fix it?

Answer: The N+1 problem occurs when you fetch a list of entities (1 query) and then access a related entity for each item in a loop, causing N additional queries.

  • Fix: Load related data intentionally with Include, filtered includes, projections, or explicit loading. Avoid lazy loading in hot paths because it can hide extra database round trips.
  • Example: await context.Orders.Include(o => o.Customer).ToListAsync();
  • Tradeoff: For multiple collection navigations, consider split queries or projections to avoid cartesian explosion and loading columns you do not need.

Rarity: Very Common Difficulty: Medium


12. Explain the Repository Pattern. Why use it with EF Core?

Answer: The Repository Pattern mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.

  • Pros: Decouples the application from the specific data access technology (EF Core), makes unit testing easier (can mock the repository), and centralizes data access logic.
  • Cons/Debate: EF Core's DbContext is already an implementation of the Repository/Unit of Work pattern. Adding another layer can sometimes be redundant ("abstraction over abstraction").

Rarity: Common Difficulty: Hard


REST APIs & Web Services

13. What are the HTTP Verbs and their typical usage?

Answer:

  • GET: Retrieve a resource. Safe and idempotent; should not change server state.
  • POST: Create a resource or trigger an action. Usually not idempotent unless you design it with an idempotency key.
  • PUT: Replace a resource at a known URI. Idempotent when repeated with the same payload.
  • PATCH: Partially update a resource. Idempotency depends on the patch format and server behavior.
  • DELETE: Remove a resource. Usually treated as idempotent because repeating it leaves the resource deleted.

Rarity: Common Difficulty: Easy

14. What is the difference between 401 Unauthorized and 403 Forbidden?

Answer:

  • 401 Unauthorized: The user is not authenticated. The client should log in and try again. "I don't know who you are."
  • 403 Forbidden: The user is authenticated but does not have permission to access the resource. "I know who you are, but you can't do this."

Rarity: Common Difficulty: Easy


Testing & Best Practices

15. What is the difference between Unit Tests and Integration Tests?

Answer:

  • Unit Tests: Test a small unit of code (usually a method) in isolation. Dependencies are mocked (using tools like Moq). Fast and reliable.
  • Integration Tests: Test how different parts of the application work together (e.g., API endpoint + Database). Slower but verify the actual system behavior.

Rarity: Common Difficulty: Easy


16. How do you Mock dependencies in Unit Tests?

Answer: Mocking frameworks like Moq or NSubstitute are used to create fake implementations of interfaces.

  • Purpose: To isolate the class under test. For example, if testing a UserService, you mock the IUserRepository so you don't hit the real database.
  • Example (Moq):
var mockRepo = new Mock<IUserRepository>();
mockRepo.Setup(repo => repo.GetById(1)).Returns(new User { Id = 1, Name = "Test" });
var service = new UserService(mockRepo.Object);

Rarity: Common Difficulty: Medium


17. What are SOLID principles? Give an example of one.

Answer: SOLID is an acronym for 5 design principles to make software more understandable, flexible, and maintainable.

  • Single Responsibility Principle (SRP)
  • Open/Closed Principle (OCP)
  • Liskov Substitution Principle (LSP)
  • Interface Segregation Principle (ISP)
  • Dependency Inversion Principle (DIP)
  • Example (DIP): High-level modules should not depend on low-level modules. Both should depend on abstractions. This is the basis for Dependency Injection.

Rarity: Common Difficulty: Hard


18. What is Boxing and Unboxing? Why avoid it?

Answer:

  • Boxing: Converting a value type (like int) to a reference type (object). It allocates memory on the heap.
  • Unboxing: Converting the reference type back to the value type.
  • Performance: Both are expensive operations (memory allocation, type checking). Generics (List<T>) help avoid boxing/unboxing compared to older collections (ArrayList).

Rarity: Common Difficulty: Medium


19. What is the using statement in C#?

Answer: The using statement provides a convenient syntax that ensures the correct use of IDisposable objects.

  • Mechanism: It automatically calls the Dispose() method on the object when the block is exited (even if an exception occurs).
  • Modern Syntax: using var file = File.OpenRead("path"); (no braces needed, disposed at end of scope).

Rarity: Common Difficulty: Easy


20. Explain the concept of Middleware in the context of the "Chain of Responsibility" pattern.

Answer: ASP.NET Core Middleware is a classic implementation of the Chain of Responsibility pattern.

  • Pattern: A request is passed along a chain of handlers. Each handler decides either to process the request or to pass it to the next handler in the chain.
  • Application: In .NET, the RequestDelegate represents the next handler. Middleware components are chained to form the request pipeline.

Rarity: Uncommon Difficulty: Hard

Newsletter subscription

Weekly career tips that actually work

Get the latest insights delivered straight to your inbox

Stand Out to Recruiters & Land Your Dream Job

Join thousands who transformed their careers with AI-powered resumes that pass ATS and impress hiring managers.

Start building now

Share this post

Cut Your Resume Writing Time by 90%

The average job seeker spends 3+ hours formatting a resume. Our AI does it in under 15 minutes, getting you to the application phase 12x faster.