.NET Interview Questions and Answers
100 .NET interview questions across 10 topics: C# Fundamentals & Modern Language Features, .NET Runtime, CLR & Memory Management, ASP.NET Core & Web APIs, Dependency Injection & Configuration, Entity Framework Core & Data Access, Asynchronous & Multithreaded Programming, Security, Identity & Authentication, High Performance & Low Allocation Coding, Unit & Integration Testing, and Clean Architecture & Microservices. They cover Junior, Mid-level, and Senior levels, and every question has a short answer to give in the interview, a deeper explanation, common mistakes, and links to official documentation with a last-reviewed date.
Topics
C# Fundamentals & Modern Language Features
10 questions
.NET Runtime, CLR & Memory Management
10 questions
ASP.NET Core & Web APIs
10 questions
Dependency Injection & Configuration
10 questions
Entity Framework Core & Data Access
10 questions
Asynchronous & Multithreaded Programming
10 questions
Security, Identity & Authentication
10 questions
High Performance & Low Allocation Coding
10 questions
Unit & Integration Testing
10 questions
Clean Architecture & Microservices
10 questions
C# Fundamentals & Modern Language Features Interview Questions (.NET)
- What is the basic difference between Value Types and Reference Types in C#, and how are they stored in memory?
- What are Boxing and Unboxing in C#, and why should they be avoided in high-volume code paths?
- How do Record and Class differ in modern C#, and when should you prefer Records?
- How do Nullable Reference Types work in C#, and what is the role of Static Flow Analysis?
- How have Pattern Matching and switch expressions developed in modern C#?
- How do Delegate, Action, and Func differ, and how does the event keyword protect encapsulation?
- What are Span<T> and ReadOnlySpan<T>, and how do they process data without Heap allocation (Zero-Allocation)?
- How do you implement the IDisposable Pattern, and how do Managed and Unmanaged resources differ?
- What is Variance in C#, and how do Covariance (out) and Contravariance (in) differ?
- What are C# Source Generators, and how do they improve on runtime Reflection?
.NET Runtime, CLR & Memory Management Interview Questions (.NET)
- How does the .NET Garbage Collector work, and what are the three generations (Gen 0, Gen 1, Gen 2)?
- What is the Large Object Heap (LOH) in .NET, and why is it prone to Memory Fragmentation?
- What is the fundamental difference between Workstation GC and Server GC in .NET?
- How does the CLR run C# code, what is the Common Intermediate Language (CIL/IL), and what does the JIT do?
- What is Native AOT in .NET 8+, and what benefits and limitations does it bring?
- How do Tiered Compilation and Dynamic PGO work?
- How do you use AssemblyLoadContext to isolate and unload Plugins dynamically?
- What is Memory Pinning and the fixed statement, and how do they affect the Garbage Collector?
- What is ThreadPool Starvation caused by Sync-over-Async (.Result / .Wait())?
- How do you diagnose memory failures and Deadlocks on production Linux environments with dotnet-dump and dotnet-trace?
ASP.NET Core & Web APIs Interview Questions (.NET)
- How do Minimal APIs differ from traditional Controllers in ASP.NET Core?
- How does the Middleware Pipeline work in ASP.NET Core, and why is registration order critical?
- How was Kestrel designed to become one of the world's fastest web servers, and what is a Reverse Proxy?
- What are the five ASP.NET Core Controller Filter stages, and in what order do they run?
- How does Model Binding work in ASP.NET Core, and how do [FromBody], [FromRoute], and [FromQuery] differ?
- How do IOptions, IOptionsSnapshot, and IOptionsMonitor differ in the Options Pattern?
- How do you apply the built-in Rate Limiting Middleware in .NET 7+?
- What is the ProblemDetails standard (RFC 7807), and how do you enable it for ASP.NET Core errors?
- How does Output Caching in .NET 7+ improve on the older Response Caching Middleware?
- How do you run continuous background tasks with BackgroundService, and what are the risks of injecting Scoped services into it?
Dependency Injection & Configuration Interview Questions (.NET)
- How do the Transient, Scoped, and Singleton service lifetimes differ in .NET?
- What is Captive Dependency in the .NET DI container, and how do you detect and prevent it?
- How do Keyed Services added in .NET 8 work, and how do they address multiple implementations?
- Who calls Dispose() on services implementing IDisposable when using the .NET DI container?
- How does Scrutor use Assembly Scanning to register services automatically with Convention-over-Configuration?
- Why is the Service Locator pattern (injecting IServiceProvider directly) an Anti-pattern in C#?
- How do you register and resolve Open Generics such as IRepository<> in the .NET container?
- What does the [FromServices] Attribute do, and when would you inject a service into an Action method instead of the constructor?
- What happens when multiple classes implementing the same interface are registered in the .NET container, and how do you resolve them all?
- When should you replace .NET's built-in container with an advanced container such as Autofac?
Entity Framework Core & Data Access Interview Questions (.NET)
- How does the EF Core Change Tracker work, and why should you use AsNoTracking() for read queries?
- What is Cartesian Explosion when including multiple relationships, and how do Split Queries solve it?
- Why is DbContext not thread-safe, and what does DbContext Pooling do?
- How do you use Global Query Filters for soft deletion and Multi-Tenancy in EF Core?
- Why is automatically calling Database.Migrate() when a server starts discouraged, and what are Migration Bundles?
- How do FromSqlInterpolated and FromSqlRaw differ in EF Core, and which is safe from SQL Injection?
- How do you implement Optimistic Concurrency and resolve conflicts with RowVersion in EF Core?
- What are Compiled Queries in EF Core, and when are they worth using?
- How do ExecuteUpdate and ExecuteDelete in EF Core 7+ improve performance for bulk operations?
- Compare EF Core inheritance strategies: Table-Per-Hierarchy (TPH) and Table-Per-Type (TPT).
Asynchronous & Multithreaded Programming Interview Questions (.NET)
- How do Task<T> and ValueTask<T> differ, and when should you choose ValueTask in C# methods?
- What does ConfigureAwait(false) do, why was it important for desktop apps and libraries, and how has its role changed in ASP.NET Core?
- How do you pass and handle CancellationToken through asynchronous call chains in ASP.NET Core?
- How do Task.WhenAll and Task.WaitAll differ when managing concurrent tasks in C#?
- How do you use SemaphoreSlim for Concurrency Throttling and protecting sensitive resources in async code?
- How does System.Threading.Channels work, and what does it offer for the Producer-Consumer pattern?
- What is IAsyncEnumerable<T>, and how does it stream large result sets in ASP.NET Core?
- What is the fundamental difference between ThreadLocal<T> and AsyncLocal<T> in asynchronous .NET code?
- Why is async void forbidden in C#, and what is its only acceptable use?
- How do you process asynchronous work in parallel with Parallel.ForEachAsync in .NET 6+?
Security, Identity & Authentication Interview Questions (.NET)
- How do you safely configure JWT validation with TokenValidationParameters in ASP.NET Core?
- How do you implement Policy-Based Authorization and inject IAuthorizationRequirement requirements?
- What is the .NET Data Protection API, and where should its keys be stored for production servers running across multiple instances?
- How do ASP.NET Core view engines and Controllers protect an application against Cross-Site Scripting (XSS)?
- How does IAntiforgery protect web forms, and when is it unnecessary in a REST API?
- How do you manage secrets and connection strings securely with Secret Manager in development and Azure Key Vault in production?
- How do you protect Dapper and ADO.NET queries against SQL Injection?
- What is Overposting / Mass Assignment in ASP.NET Core, and how do you prevent it?
- Why is System.Random unsafe for security purposes, and what is the cryptographic alternative?
- What does Always Encrypted with Secure Enclaves in SQL Server and .NET provide?
High Performance & Low Allocation Coding Interview Questions (.NET)
- How do ArrayPool<T> and MemoryPool<T> eliminate Garbage Collector pressure (GC Pressure)?
- How do you use BenchmarkDotNet to accurately measure C# performance, and what are the golden measurement rules?
- Why are string objects Immutable, and when should you use StringBuilder or String.Create?
- What is Method Inlining, and when should you use [MethodImpl(MethodImplOptions.AggressiveInlining)]?
- How do you monitor live performance metrics and memory usage in .NET with System.Diagnostics.Metrics and OpenTelemetry?
- What are SIMD instructions and Hardware Intrinsics in .NET, and how do they speed up numeric array processing?
- How does Struct Layout & Padding affect memory use and byte alignment in C#?
- Why is GeneratedRegex in .NET 7+ better than creating new Regex() objects at runtime?
- Why should you set Initial Capacity when creating List<T> and Dictionary<TKey, TValue>?
- Why is System.Text.Json much faster than Newtonsoft.Json (Json.NET), and what architecture does it use?
Unit & Integration Testing Interview Questions (.NET)
- What is xUnit's design philosophy, and how does it isolate tests by creating a new class instance for each test?
- How do you use WebApplicationFactory<Program> for real integration tests of ASP.NET Core servers?
- Compare Moq and NSubstitute for creating mocks in C# tests.
- What do expressive assertion libraries such as FluentAssertions or AwesomeAssertions offer in .NET tests?
- How do you use Testcontainers.MsSql or Testcontainers.PostgreSql to test EF Core against real databases?
- What is TimeProvider, added in .NET 8, and how does it simplify testing code that depends on time and timers?
- How do you write Architecture Tests with libraries such as NetArchTest in .NET?
- What is Mutation Testing with Stryker.NET, and how does it measure the true quality of assertions?
- How do [Fact] and [Theory] differ in xUnit, and how do you pass datasets with [InlineData]?
- How do you test HttpClient safely without sending real network requests using MockHttpMessageHandler?
Clean Architecture & Microservices Interview Questions (.NET)
- How do you organize Clean Architecture layers in .NET Enterprise solutions?
- What is CQRS, and how does MediatR help separate reads and writes in C# projects?
- What are MediatR Pipeline Behaviors, and how do they implement Aspect-Oriented Programming (AOP)?
- How do Entities, Value Objects, and Aggregate Roots differ in DDD?
- What is Event Sourcing, and how do event stores differ from traditional databases?
- What is the Dual-Write problem, and how does the Transactional Outbox pattern with MassTransit solve it?
- How do you design Resilience Pipelines with Polly v8 integrated into .NET 8?
- How do you build fast gRPC services in .NET, and what do .proto files do?
- How do you implement Distributed Tracing with Activity and OpenTelemetry in .NET?
- What is .NET Aspire, and how does it simplify building and monitoring distributed Cloud-Native applications?