🔷 .NET Interview Questions

Master .NET interviews with questions on C#, ASP.NET Core, Entity Framework, and the .NET ecosystem

15-Minute .NET Cheatsheet

Quick reference for last-minute interview preparation

🔷 C# Fundamentals

Value vs Ref: struct (stack) vs class (heap)
Boxing: Value type → object (heap allocation)
ref/out/in: Pass by reference modifiers
nullable: int? nullable value types
var: Compile-time inference, strongly typed

✨ Modern C# (8-12)

Records: Immutable data with value equality
Pattern matching: is, switch expressions
Nullable refs: string? null safety
Init-only: { get; init; } properties
Primary constructors: class Person(string name)

🌐 ASP.NET Core

Middleware: Request pipeline, app.Use*()
DI: AddScoped, AddTransient, AddSingleton
Minimal APIs: app.MapGet(), app.MapPost()
Filters: Action, Result, Exception filters
Configuration: appsettings.json, IOptions<T>

🗃️ Entity Framework Core

DbContext: Unit of work, change tracking
Loading: Eager (.Include), Lazy, Explicit
Migrations: Add-Migration, Update-Database
Tracking: AsNoTracking() for read-only
Relationships: One-to-Many, Many-to-Many

⚡ Async Programming

async/await: Non-blocking I/O operations
Task vs ValueTask: Heap vs stack allocation
Task.WhenAll: Parallel async operations
ConfigureAwait(false): Library code optimization
CancellationToken: Cooperative cancellation

🔍 LINQ Essentials

Query: Where, Select, OrderBy, GroupBy
Aggregation: Sum, Count, Average, Max, Min
Deferred: Query executed on enumeration
IQueryable: DB queries, expression trees
IEnumerable: In-memory, delegate chains

🔄 Dependency Injection Lifetimes

Transient: New instance every request
Scoped: One instance per HTTP request
Singleton: One instance for app lifetime

⚠️ Common Interview Gotchas

• string is reference type but immutable
• Dispose vs Finalize (deterministic vs GC)
• async void only for event handlers
• DbContext is not thread-safe
• Captive dependency (scoped in singleton)
• N+1 query problem with lazy loading

.NET Framework: Windows-only, legacy platform (up to version 4.8). Includes WPF, Windows Forms, ASP.NET. No longer actively developed for new features.

.NET Core: Cross-platform, open-source reimplementation (versions 1.0-3.1). Designed for cloud, microservices, and containers.

.NET 5+: Unified platform (5, 6, 7, 8, 9...). Combines .NET Framework and .NET Core. Cross-platform, modern, and the future of .NET. Even versions are LTS (Long-Term Support).

C#

Records are reference types designed for immutable data models with value-based equality. Introduced in C# 9.0, they provide a concise syntax for creating data-centric types.

Key Differences:

  • Records have value-based equality by default (classes have reference equality)
  • Records support with-expressions for non-destructive mutation
  • Records have built-in ToString() implementation
  • Records are immutable by default (but can be made mutable)
C#

async/await is C#'s syntax for asynchronous programming, making it easier to write non-blocking code. The Task Parallel Library (TPL) provides the foundation for parallel and asynchronous programming.

C#

Dependency Injection (DI) is a design pattern where objects receive their dependencies from external sources rather than creating them. ASP.NET Core has built-in DI container that manages object lifetimes.

Service Lifetimes:

  • Transient: Created each time they're requested
  • Scoped: Created once per client request (HTTP request)
  • Singleton: Created once for the application lifetime
C#

LINQ (Language Integrated Query) provides a uniform way to query different data sources using C# syntax. It supports method syntax and query syntax for writing expressive queries.

C#

Entity Framework Core is a modern Object-Relational Mapper (ORM) for .NET. It enables developers to work with databases using .NET objects, eliminating the need for most data-access code.

C#

Middleware is software assembled into an application pipeline to handle requests and responses. Each component can perform operations before and after the next component in the pipeline.

C#

Delegates: Type-safe function pointers that reference methods.
Events: Special delegates for the publisher-subscriber pattern.
Lambda Expressions: Anonymous functions for concise inline code.

C#

Value Types: Stored on the stack, contain actual data (int, struct, enum).
Reference Types: Stored on the heap, contain reference to data (class, string, array).

C#

IEnumerable<T>: In-memory collection, executes queries in-process using LINQ to Objects.
IQueryable<T>: Translates queries to external query language (e.g., SQL), executes on database.

C#

The .NET Garbage Collector (GC) automatically manages memory allocation and release. It uses a generational algorithm with three generations (0, 1, 2) to optimize performance.

C#

Pattern matching enables you to test whether a value has a certain shape and extract information from it. C# supports multiple pattern types introduced from C# 7.0 through C# 11.

C#

Nullable Reference Types (C# 8.0+) help prevent null reference exceptions by making nullability explicit in the type system. The compiler warns about potential null references at compile time.

C#

Span<T> and Memory<T> (C# 7.2+) provide type-safe, memory-efficient access to contiguous memory without allocations. Span is stack-only, while Memory can be used in async methods and stored in fields.

C#

API versioning allows you to evolve your API while maintaining backward compatibility. ASP.NET Core supports multiple versioning strategies: URL path, query string, header, and media type.

C#

🧠 Memory Management

.NET uses generational GC with three generations (0, 1, 2) and Large Object Heap for objects over 85KB.

csharp
csharp

🌐 ASP.NET Core Framework

csharp
csharp
csharp
csharp

Interview Tips for .NET