Q1. What is the difference between .NET Framework, .NET Core and modern .NET?
Short answer: Modern .NET (current: .NET 10) is the unified, cross-platform successor to the Windows-only .NET Framework.
Strong answer: .NET Framework is Windows-only and legacy. .NET Core unified and cross-platformed the runtime; from .NET 5 onward it is just “.NET”, with .NET 10 the current LTS. Modern .NET is open-source, cross-platform, high-performance and the target for all new work. Legacy apps may still run on .NET Framework 4.8.
Likely follow-up: Why would you still target .NET Framework today?
What the interviewer is checking: Awareness of the current .NET landscape.
Common mistake: Treating .NET Core and .NET Framework as interchangeable.
Q2. Explain value types vs reference types in C#.
Short answer: Value types hold data directly (stack/inline); reference types hold a reference to heap data.
Strong answer: Value types (structs, int, bool, enums) contain their data and are copied by value; reference types (classes, strings, arrays) hold a reference, so copies share the same object. This affects equality, mutation and performance. Understand boxing (value → object) and its cost, and prefer structs for small, immutable data.
Likely follow-up: What is boxing and when does it hurt performance?
What the interviewer is checking: Core language and memory understanding.
Common mistake: Assuming structs behave like classes on assignment.
Q3. How does async/await work in C#?
Short answer: await suspends a method without blocking the thread, resuming on completion via a state machine.
Strong answer: async/await lets you write asynchronous code sequentially; the compiler builds a state machine that releases the thread on await and resumes when the awaited Task completes. It scales I/O-bound work by not blocking threads. Avoid async void (except event handlers), avoid .Result/.Wait() (deadlocks), and flow cancellation tokens.
Likely follow-up: Why can .Result cause a deadlock?
What the interviewer is checking: Correct async understanding.
Common mistake: Blocking on async code with .Result/.Wait().
Q4. What is dependency injection in ASP.NET Core?
Short answer: A built-in IoC container registers services with lifetimes and injects them via constructors.
Strong answer: ASP.NET Core has a built-in DI container. You register services in the composition root with a lifetime — Singleton, Scoped (per request) or Transient — and they are injected via constructors. This decouples components and eases testing. Choosing the right lifetime (e.g., Scoped for DbContext) is critical.
Likely follow-up: What goes wrong if you inject a Scoped service into a Singleton?
What the interviewer is checking: DI and lifetime understanding.
Common mistake: Captive dependencies — a Singleton holding a Scoped service.
Q5. How does Entity Framework Core work, and what are common pitfalls?
Short answer: An ORM mapping classes to tables with change tracking; watch N+1 queries and tracking overhead.
Strong answer: EF Core maps entities to tables, tracks changes and generates SQL. Common pitfalls: N+1 queries (fix with Include/projection), loading more than needed (use AsNoTracking for reads and Select projections), and lazy loading surprises. Understand LINQ-to-SQL translation and inspect the generated queries.
Likely follow-up: How do you avoid the N+1 problem?
What the interviewer is checking: Practical data-access skill.
Common mistake: Ignoring the generated SQL and loading whole graphs.
Q6. What is the middleware pipeline in ASP.NET Core?
Short answer: An ordered chain of components that each handle the request/response and call the next.
Strong answer: ASP.NET Core processes requests through an ordered middleware pipeline configured in the app startup — each middleware can act on the request, short-circuit, or pass to the next via next(). Order matters (e.g., authentication before authorization, exception handling first). Common middleware: routing, auth, CORS, static files.
Likely follow-up: Why must UseAuthentication come before UseAuthorization?
What the interviewer is checking: Request-pipeline understanding.
Common mistake: Adding middleware in the wrong order.
Q7. Explain garbage collection and IDisposable in .NET.
Short answer: The GC reclaims managed memory; IDisposable releases unmanaged resources deterministically.
Strong answer: The generational GC frees managed objects automatically. Unmanaged resources (files, sockets, DB connections) are not GC-timed, so implement IDisposable and use using/using-declarations to release them deterministically. Understand the dispose pattern and avoid finalizers unless wrapping unmanaged handles.
Likely follow-up: Why prefer using over relying on a finalizer?
What the interviewer is checking: Resource-management understanding.
Common mistake: Leaking unmanaged resources by not disposing.
Q8. How would you build a scalable Web API in ASP.NET Core?
Short answer: Stateless controllers, DTOs, async I/O, caching, pagination and proper status codes.
Strong answer: Keep controllers thin and stateless, use DTOs and model validation, make I/O async, add response caching/ETags, paginate collections, return correct status codes, and centralize errors. Add observability (logging, metrics, health checks) and scale horizontally behind a load balancer. Consider minimal APIs for lightweight endpoints.
Likely follow-up: How would you handle a slow downstream dependency?
What the interviewer is checking: API architecture maturity.
Common mistake: Synchronous, stateful controllers that do not scale.