.NET Interview Questions

50 unique .NET interview questions with detailed answers covering CLR, C#, ASP.NET Core, EF Core, and more.

.NET is a development platform created by Microsoft to build secure, scalable, and high-performance applications. It provides a runtime environment, libraries, and tools for multiple languages like C#, F#, and VB.NET.
CLR is the core runtime of .NET that manages execution of programs, memory allocation, garbage collection, security, exception handling, and interoperability between .NET languages.
Managed code runs under the control of the CLR, with services like garbage collection and type safety. Unmanaged code executes directly on the OS, like C/C++ binaries, and requires manual memory management.
Value types store data directly in memory and are usually stored on the stack (e.g., int, bool, struct). Reference types store a reference to the data on the heap (e.g., class, string, array) and can be null.
Garbage collection is an automatic memory management feature that frees objects that are no longer referenced, reducing memory leaks and improving performance.
An assembly is a compiled code library used for deployment, versioning, and security. It can be a DLL or EXE and contains metadata and MSIL code.
Strong naming gives an assembly a unique identity using its name, version, culture, and public key token. It prevents conflicts and ensures version integrity.
Early binding occurs at compile time, providing better performance and type safety. Late binding occurs at runtime, providing flexibility but slower execution.
Boxing converts a value type to an object type. Unboxing converts an object back to a value type.
An interface defines a contract with only method signatures and properties. An abstract class can have implementations, fields, and constructors in addition to abstract members.
.NET Framework is Windows-only, mature, and used for desktop and web apps. .NET Core is cross-platform and modular. .NET 5+ unifies .NET Core and .NET Framework into a single cross-platform platform.
NuGet is a package manager for .NET that allows developers to easily add, update, and manage third-party libraries and dependencies in projects.
Delegates are type-safe function pointers that can reference methods with a specific signature. They are used for callbacks and event handling.
An event is a message sent by an object to signal the occurrence of an action. Events use delegates to notify subscribers about changes or actions.
Generics allow you to define classes, methods, or interfaces with a placeholder for data types, enabling type safety and code reusability without boxing/unboxing overhead.
IEnumerable executes queries in-memory, suitable for collections. IQueryable can translate queries to the underlying data source (like SQL), enabling deferred execution and optimized queries.
LINQ (Language Integrated Query) provides a consistent way to query objects, collections, databases, XML, or JSON using C# syntax with strong typing and IntelliSense support.
Async and await are keywords used for asynchronous programming, allowing non-blocking code execution and improved performance in I/O-bound operations.
Thread represents a low-level OS thread. Task is a higher-level abstraction representing asynchronous work, which may run on existing threads from the thread pool.
DI is a design pattern where dependencies are injected into a class rather than being created internally, promoting loose coupling and easier testing.
Common patterns include Singleton, Factory, Repository, Observer, Strategy, and MVC. They provide reusable solutions to recurring software problems.
String is immutable, and any modification creates a new object. StringBuilder is mutable, allowing efficient modifications without creating new objects.
Nullable types (e.g., int?) allow value types to hold null values, useful for database and optional fields scenarios.
Reflection allows inspection of metadata about assemblies, types, and members at runtime. It enables dynamic object creation, method invocation, and attribute discovery.
Server-side Blazor runs components on the server and communicates via SignalR. Client-side (WebAssembly) runs in the browser directly without server roundtrips for UI rendering.
GC uses three generations (0, 1, 2). Gen 0 holds short-lived objects collected frequently. Gen 1 is a buffer. Gen 2 holds long-lived objects collected infrequently. This improves performance by focusing collection on short-lived objects.
Value types (e.g., int, struct) are stored on the stack and copied by value. Reference types (e.g., class, array) are stored on the heap and copied by reference.
Middleware is software that sits in the request pipeline to handle HTTP requests and responses. Examples include authentication, logging, and routing components.
IActionResult is a non-generic interface for returning HTTP responses. ActionResult<T> combines a return type T with IActionResult, providing type safety and flexibility in Web API responses.
A strongly-typed view is bound to a specific model class, allowing IntelliSense, compile-time checking, and easier data binding in Razor pages.
Model represents the data, View renders the UI, and Controller handles requests and updates the Model or View accordingly.
GET requests retrieve data and should be idempotent. POST requests send data to the server to create or modify resources.
Filters are attributes that run before or after controller actions to handle cross-cutting concerns like authorization, logging, caching, or exception handling.
REST is an architectural style using HTTP methods, lightweight JSON, and stateless communication. SOAP is a protocol using XML, strict contracts, and often heavier payloads.
EF Core is an Object-Relational Mapper (ORM) for .NET that allows developers to work with databases using strongly-typed C# objects, LINQ queries, and migrations.
Code First: create classes first, then database. Database First: generate classes from an existing database. Model First: design the model visually and generate classes and database.
Lazy loading defers the loading of related data until it is explicitly accessed, reducing initial query overhead.
Migrations are a way to incrementally update the database schema as the model evolves, keeping it in sync with the code.
ASP.NET Core Identity is a membership system for user authentication and authorization. Authentication schemes include Cookies, JWT, and external providers like Google or Facebook.
JWT (JSON Web Token) is a compact, URL-safe token used for authentication and authorization. It contains claims and is validated by APIs to authorize requests.
Repository abstracts data access, providing a collection-like interface. It improves maintainability, testability, and separation of concerns in applications.
Unit of Work maintains a list of objects affected by a business transaction and coordinates writing changes to the database in a single operation.
MediatR is a mediator library for .NET that implements CQRS and decouples request handling from business logic using requests, handlers, and notifications.
CQRS (Command Query Responsibility Segregation) separates read and write operations into different models, improving scalability, performance, and maintainability.
Web API is lightweight, uses HTTP/REST, JSON/XML, and is cross-platform. WCF is a service-oriented framework supporting multiple protocols (SOAP, TCP) but is heavier and mostly Windows-only.
SignalR is a library for real-time communication, allowing server code to push updates to clients over WebSockets or fallback transports.
Task represents an asynchronous operation. ValueTask is a lightweight alternative that avoids allocations when the result is already available synchronously.
ConfigureAwait(true) resumes on the original context (UI thread). ConfigureAwait(false) allows continuation on any thread, improving performance in library code.
IHostedService defines background services that run when the app starts and stops gracefully, used for tasks like scheduled jobs, queues, or timers.
ViewData is a dictionary for passing data from controller to view. ViewBag is a dynamic wrapper over ViewData. TempData persists data across redirects using session storage.

Looking to ace your .NET interview? Explore our training programmes.