.NET 8 & C# 12 Interview Questions

Summary

Senior-level .NET interview questions with concise answers, follow-up questions and production scenarios.

C# 12

Classes vs Records

Struct vs Class

Interface vs Abstract Class

Generics

Delegates

Events

Pattern Matching

Nullable Reference Types

LINQ

Async / Await

Task vs ValueTask


.NET 8

Dependency Injection

Configuration

Logging

Options Pattern

Middleware

Filters

Exception Handling

Minimal APIs

Controllers

EF Core

Caching

Authentication & Authorization


ASP.NET Core

Middleware

What is middleware?

Answer:

Middleware is a component in the ASP.NET Core request pipeline that can process an HTTP request and response.

It can:

  1. Inspect the request
  2. Modify the request
  3. Call the next middleware
  4. Modify the response
  5. Short-circuit the pipeline

Request Pipeline

Middleware vs Filters

Answer:

Middleware operates at the HTTP pipeline level, while filters operate within the MVC/controller or endpoint execution pipeline.

Interview follow-up

When would you choose middleware over a filter?

Does middleware execute on the way back?

Answer:

Yes. Middleware surrounding next() can execute code both before and after the downstream component.

Middleware A

    ├── Before


Middleware B

    ├── Before


Endpoint


    ├── After

Middleware B


    ├── After

Middleware A
 
## Scoped vs Singleton vs Transient
 
## Model Binding
 
## Action Filters
 
## Exception Filters
 
---
 
# Production & Architecture
 
## API Versioning
 
## Resilience
 
## Observability
 
## Distributed Caching
 
## Messaging
 
## Horizontal Scaling