November 22, 2025
9 min read

Backend Developer (C#/.NET) Interview Questions: Complete Guide

interview
career-advice
job-search
Backend Developer (C#/.NET) Interview Questions: Complete Guide
MB

Milad Bonakdar

Author

Master C# and .NET backend development with essential interview questions covering ASP.NET Core, Entity Framework, Dependency Injection, and system design.


Introduction

C# and .NET have evolved significantly, becoming a powerful, cross-platform ecosystem for building high-performance backend systems. With the advent of .NET Core (and now just .NET 5+), it is a top choice for cloud-native applications, microservices, and enterprise solutions.

This guide covers essential interview questions for Backend Developers specializing in C# and .NET. We explore language fundamentals, ASP.NET Core architecture, database interactions with Entity Framework, and best practices to help you prepare for your next interview.


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 are keywords used for asynchronous programming.

  • Mechanism: When an await keyword is encountered, the execution of the method is paused, and the thread is released back to the thread pool to handle other requests. When the awaited task completes, execution resumes (potentially on a different thread).
  • Scalability: In a web server (like Kestrel), threads are a limited resource. If a thread blocks waiting for I/O (database, network), it can't handle other requests. Async allows the server to handle many more concurrent requests with fewer threads by not blocking them during I/O operations.

Rarity: Very Common Difficulty: Medium


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

Answer: Dependency Injection is a design pattern where a class's dependencies are provided from the outside rather than created internally.

  • In .NET: ASP.NET Core has a built-in DI container. You register services in Program.cs (or Startup.cs in older versions) and inject them via constructor injection.
  • Lifetimes:
    • Transient: Created every time they are requested.
    • Scoped: Created once per client request (HTTP request).
    • Singleton: Created the first time they are requested and shared by all subsequent requests.

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 (now just .NET): A cross-platform, open-source, and modular implementation. It runs on Windows, Linux, and macOS. It is optimized for high performance and cloud deployments.
  • Key Differences: Cross-platform support, microservices architecture friendly, higher performance, side-by-side versioning.

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 try-catch blocks in every controller, you should use middleware for global exception handling.

  • UseExceptionHandler: Built-in middleware that catches exceptions, logs them, and re-executes the request in an alternate pipeline (usually pointing to an error page or API response).
  • Custom Middleware: You can write custom middleware to catch exceptions and return a standardized JSON error response (e.g., ProblemDetails).

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: Use Eager Loading with the .Include() method. This generates a SQL JOIN to fetch the related data in a single query.
  • Example: context.Orders.Include(o => o.Customer).ToList();

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.
  • POST: Create a new resource. Not Idempotent.
  • PUT: Update/Replace an existing resource. Idempotent.
  • PATCH: Partially update a resource. Not necessarily Idempotent (but usually is).
  • DELETE: Remove a resource. Idempotent.

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

Related Posts

Recent Posts

Weekly career tips that actually work

Get the latest insights delivered straight to your inbox