Technology

C# and .NET Interview Questions and Answers

C# and .NET are widely used for enterprise applications, web APIs and cloud services. These C# and .NET interview questions cover types, OOP and the CLR for freshers, then LINQ, async/await, dependency injection, ASP.NET Core, Entity Framework Core and performance for experienced .NET developers.

30 questions · Updated

Reading answers is not the same as saying them.Practise C# and .NET questions out loud and get a score, what you missed and a model answer for each one.
Practise free with AI
C# and .NET Interview Questions with answers. Examples: What is the difference between .NET Framework, .NET Core and .NET? What is the difference between value types and reference types? What is the difference between an abstract class and an interface in C#? What is LINQ?
C# and .NET Interview Questions: 30 questions with model answers on this page.

Basic C# and .NET interview questions

Fundamentals, definitions and simple scenarios. Good for freshers and warm-ups.

1. What is the difference between .NET Framework, .NET Core and .NET?

Answer flow · 3 steps
  1. .NET Framework is the original Windows-only platform, now only maintained. .NET Core was the cross-platform, open-source rewrite that runs on Windows, Linux and macOS.

  2. From version 5 it is simply called .NET (such as .NET 8 and .NET 9), unifying the platform.

  3. New projects should use the current long-term support version of .NET.

2. What is the difference between value types and reference types?

Answer flow · 3 steps
  1. Value types, such as int, double, bool, struct and enum, hold their data directly and are copied on assignment.

  2. Reference types, such as class, string, arrays and delegates, hold a reference to an object on the managed heap, so two variables can point to the same object.

  3. Boxing converts a value type into an object, which costs performance.

3. What is the difference between an abstract class and an interface in C#?

Answer flow · 3 steps
  1. An abstract class can have fields, constructors, implemented methods and abstract members, and a class can inherit only one.

  2. An interface defines a contract that a class can implement many of; since C# 8 interfaces can have default implementations but still no instance fields.

  3. I use interfaces for capabilities and dependency injection, and abstract classes for shared base behaviour.

4. What are the CLR, IL and JIT compilation?

Answer flow · 4 steps
  1. C# code is compiled into Intermediate Language (IL) stored in assemblies (DLLs).

  2. The Common Language Runtime (CLR) loads them and the just-in-time compiler converts IL into native machine code when methods are first called.

  3. The CLR also provides garbage collection, type safety and exception handling.

  4. Native AOT can compile apps ahead of time for faster start-up.

5. What is the difference between a struct and a class?

Answer flow · 3 steps
  1. A struct is a value type, copied on assignment and usually stored inline, which suits small, immutable data such as a point or a money amount.

  2. A class is a reference type allocated on the heap and shared by reference, supporting inheritance.

  3. Large or frequently copied structs hurt performance, and readonly struct helps make them immutable.

6. Why use StringBuilder instead of string concatenation?

Answer flow · 3 steps
  1. Strings in .NET are immutable, so each concatenation in a loop creates a new string and copies the old content, which is slow and creates garbage.

  2. StringBuilder keeps a mutable buffer and appends efficiently, which suits building large strings.

  3. For a few values, interpolation ($"Hello {name}") is clearer and the compiler optimises it.

7. What is the difference between const and readonly?

const values are compile-time constants, must be primitive types or strings, are implicitly static and are copied into every assembly that uses them. readonly fields are set at declaration or in a constructor, can be any type and can differ per instance. Use readonly, or static readonly, for values that might change between versions.

8. What are properties in C#?

Properties expose data with get and set accessors while keeping the field private, so you can add validation or computed logic later without changing callers. Auto-properties, such as public string Name { get; set; }, generate the backing field. init accessors allow setting only during object creation, and required forces callers to set a property.

9. What are nullable value types and nullable reference types?

Answer flow · 3 steps
  1. A nullable value type, int?, can hold a number or null.

  2. Nullable reference types, enabled by default in new projects, make the compiler warn when a reference that might be null is used without checking; string means "never null" and string? means "may be null".

  3. Operators such as ?., ?? and ??= handle nulls concisely.

10. How does exception handling work in C#?

Answer flow · 3 steps
  1. Code that may fail goes in try, specific exceptions are caught in catch blocks from most to least specific, and finally runs cleanup regardless of the outcome. throw; rethrows while keeping the stack trace.

  2. The using statement disposes resources automatically.

  3. Exception filters (catch (HttpRequestException e) when (...)) catch only matching cases.

11. What access modifiers does C# have?

public (accessible everywhere), private (only within the type, the default for members), protected (the type and derived types), internal (within the same assembly, the default for types), protected internal (same assembly or derived types) and private protected (derived types in the same assembly). file limits a type to one source file.

Intermediate C# and .NET interview questions

Applied problems, trade-offs and questions about your own projects.

12. What is LINQ?

Answer flow · 3 steps
  1. Language Integrated Query lets you query collections, databases and XML with C# syntax, such as orders.Where(o => o.Total > 1000).OrderBy(o => o.Date).Select(o => o.Id).

  2. LINQ to Objects works on IEnumerable in memory; LINQ with Entity Framework uses IQueryable and is translated into SQL.

  3. Queries use deferred execution, running only when enumerated.

13. How do async and await work in C#?

Answer flow · 3 steps
  1. An async method returns Task or Task<T>, and await pauses the method without blocking the thread until the awaited operation completes, then continues.

  2. This frees threads to handle other requests while waiting on I/O, which improves scalability in web apps.

  3. Pitfalls are blocking with .Result or .Wait(), which can deadlock, and using async void except for event handlers.

14. What are the service lifetimes in ASP.NET Core dependency injection?

Answer flow · 3 steps
  1. Transient creates a new instance every time it is requested, Scoped creates one instance per HTTP request, and Singleton creates one instance for the whole application.

  2. DbContext is typically scoped.

  3. A singleton must not depend on a scoped service, because it would keep that instance alive beyond its request.

15. What is middleware in ASP.NET Core?

Answer flow · 3 steps
  1. Middleware are components in the request pipeline, configured in Program.cs, that each handle a request and either pass it to the next component or end it.

  2. Examples are exception handling, HTTPS redirection, static files, routing, CORS, authentication and authorisation.

  3. Order matters, for example authentication must run before authorisation.

16. What are delegates, Func, Action and events?

Answer flow · 3 steps
  1. A delegate is a type-safe reference to a method.

  2. Func<T, TResult> represents a method that returns a value and Action<T> one that returns nothing; they are used with lambdas, as in LINQ.

  3. Events are built on delegates and let a class notify subscribers, such as button.Click += OnClick, while preventing outside code from raising the event or clearing subscribers.

17. What are generics and generic constraints?

Generics let you write type-safe classes and methods that work with any type, such as List<T> or Repository<T>, without boxing or casting. Constraints restrict which types can be used: where T : class, where T : struct, where T : new() for types with a parameterless constructor, where T : IComparable<T> for an interface, or where T : notnull.

18. What are extension methods?

Answer flow · 4 steps
  1. Extension methods add methods to existing types without changing or inheriting from them.

  2. They are static methods in a static class whose first parameter has the this modifier, such as public static bool IsValidEmail(this string s).

  3. LINQ is built from extension methods on IEnumerable<T>.

  4. They should be used carefully so they do not hide important behaviour.

19. What are records?

Answer flow · 4 steps
  1. Records are reference types (or value types with record struct) designed for immutable data.

  2. They provide value-based equality, a readable ToString, and with expressions to create modified copies, such as var updated = order with { Status = "Shipped" }.

  3. A positional record, record Point(int X, int Y), declares the constructor and properties in one line.

  4. They suit DTOs and domain values.

20. How does pattern matching work in C#?

Pattern matching tests a value's shape and extracts data: type patterns (if (shape is Circle c)), property patterns ({ Status: "Paid", Amount: > 1000 }), relational patterns (< 0), logical patterns (and, or, not) and list patterns. Switch expressions combine them concisely, for example calculating a shipping fee from an order's country and weight.

21. What is the difference between Task and ValueTask, and how do you run tasks in parallel?

Answer flow · 3 steps
  1. Task represents an asynchronous operation and is the default return type.

  2. ValueTask avoids allocating when a result is often available synchronously, such as from a cache, but can only be awaited once, so it is used for hot paths.

  3. To run independent async operations at the same time, start them and await Task.WhenAll; Parallel.ForEachAsync limits concurrency for many items.

22. How does configuration work in ASP.NET Core?

Answer flow · 3 steps
  1. Configuration is combined from sources in order: appsettings.json, appsettings.{Environment}.json, user secrets in development, environment variables and command-line arguments, with later sources overriding earlier ones.

  2. The options pattern binds sections to strongly typed classes with services.Configure<T>() and injects IOptions<T>, IOptionsSnapshot or IOptionsMonitor.

  3. Secrets in production come from Key Vault or similar.

High level C# and .NET interview questions

System design, deep internals, leadership and tough follow-ups.

23. What is Entity Framework Core, and how do you avoid performance problems with it?

Answer flow · 3 steps
  1. EF Core is .NET's ORM, mapping classes to tables with DbContext and DbSet and generating SQL from LINQ.

  2. To keep it fast I use AsNoTracking for read-only queries, project to DTOs with Select to fetch only needed columns, avoid N+1 queries with Include or split queries, paginate, add indexes, and check generated SQL with logging.

  3. Compiled queries and raw SQL help hot paths.

24. What is the difference between IEnumerable and IQueryable?

Answer flow · 3 steps
  1. IEnumerable works on in-memory collections, so filters run in C# after data is loaded.

  2. IQueryable builds an expression tree that a provider such as EF Core translates into SQL, so filters, sorting and paging run in the database.

  3. Calling ToList() or switching to IEnumerable too early can load an entire table into memory.

25. How does garbage collection work in .NET?

Answer flow · 4 steps
  1. The CLR's garbage collector frees unreachable objects automatically.

  2. The heap has three generations: Gen 0 for new short-lived objects, collected often; Gen 1 as a buffer; and Gen 2 for long-lived objects.

  3. Objects over 85 KB go to the Large Object Heap.

  4. IDisposable with using statements releases unmanaged resources like file handles and connections promptly, since the GC does not manage those.

26. What is the difference between minimal APIs and controllers?

Answer flow · 3 steps
  1. Controllers group endpoints into classes with attribute routing, model binding, filters and conventions, which suits large APIs and teams used to MVC.

  2. Minimal APIs map endpoints directly with app.MapGet and similar using lambdas, with less ceremony and slightly better performance, and they now support filters, validation, route groups and OpenAPI.

  3. Both run on the same pipeline.

27. How do authentication and authorisation work in ASP.NET Core?

Authentication identifies the user through schemes such as cookies, JWT bearer tokens or OpenID Connect with an identity provider such as Microsoft Entra ID; ASP.NET Core Identity manages users and passwords. Authorisation decides what they can do, with [Authorize], roles, and policy-based rules built from requirements and handlers, including resource-based checks.

28. How do migrations and concurrency work in EF Core?

Migrations track model changes: dotnet ef migrations add creates one and the database is updated with dotnet ef database update or, better in production, a generated SQL script or migration bundle. Optimistic concurrency uses a concurrency token, such as a rowversion column; if two users edit the same row, the second save throws DbUpdateConcurrencyException, which the app resolves.

29. How do you reduce memory allocations in high-performance .NET code?

Use Span<T> and Memory<T> to work with slices of arrays and strings without copying, ArrayPool<T> and object pooling to reuse buffers, struct types and stackalloc for small temporary data, StringBuilder and string.Create for strings, and System.Text.Json source generators for serialisation. BenchmarkDotNet measures improvements, and dotnet-counters and dotnet-trace find allocation hot spots.

30. How do you test a .NET application?

Answer flow · 3 steps
  1. Unit tests use xUnit, NUnit or MSTest with Moq or NSubstitute for mocks and FluentAssertions for readable checks.

  2. Integration tests use WebApplicationFactory to host the API in memory and call it with HttpClient, with Testcontainers providing real databases.

  3. EF Core's in-memory provider behaves differently from a real database, so it is not recommended for integration tests.

Ready to test yourself?Pick your topics and level, answer by voice or text, and get instant feedback. Free.
Start a mock interview

Preparing for a backend developer interview?

See all Backend Developer interview questions, covering Node.js, Express.js, NestJS, Python, Django and more.

Related skill interview questions

More technology interview questions

HR round, company and bank interview questions

Bank and government exams

Interview questions for other fields