Key takeaways
- Mid-senior C# interviews focus on async/await, memory and the GC, LINQ/EF Core performance, ASP.NET Core DI and design.
- Expect "what happens if…" questions: deadlocks, captive dependencies, N+1 queries, thread-pool starvation.
- Bring one performance story and one production incident — interviewers at this level always ask.
With four or five years of C#, you are expected to explain why code behaves the way it does, and to avoid the classic production traps. These are the questions that come up most, with the answers interviewers listen for. The full C# interview questions page has 100+ more with code.
Language and runtime
Value types vs reference types — and what is boxing?
Value types (struct, int, DateTime) hold their data directly and are copied on assignment. Reference types (class, string, arrays) hold a reference to an object on the heap. Boxing wraps a value type in a heap object when it is treated as object or an interface — a hidden allocation that hurts performance in hot paths (for example, non-generic collections).
record vs class vs struct — when do you use each?
record (and record struct) gives value-based equality, with expressions and concise immutable models — ideal for DTOs, messages and value objects. class suits entities with identity and behaviour. struct suits small, immutable, short-lived values where avoiding heap allocations matters (roughly 16 bytes or less).
public record OrderPlaced(Guid OrderId, decimal Total, DateTimeOffset At);
var e2 = e1 with { Total = 499m }; // non-destructive copyWhat are nullable reference types, and how do you adopt them?
With <Nullable>enable</Nullable>, reference types are non-nullable by default, and the compiler warns when null might flow where it shouldn't. Adopt it file by file or project by project, fix the warnings at API boundaries first, and use ? for genuinely optional values. Avoid the ! operator except where you can prove a value isn't null.
What is the difference between IEnumerable, ICollection, IList and IReadOnlyList in APIs?
Return the most specific read-only abstraction that callers need: IReadOnlyList<T> or IReadOnlyCollection<T> for materialised results, and IEnumerable<T> only for lazy streams (and say so). Accept the most general type you actually use as parameters. Returning IEnumerable<T> from a database query invites multiple enumeration bugs.
Async and concurrency
Why is async void dangerous?
async void methods can't be awaited, and exceptions thrown inside them crash the process (they are raised on the synchronisation context) instead of reaching the caller. Use async Task everywhere except event handlers.
What is thread-pool starvation, and how does it show up?
When many threads block — on .Result, .Wait(), Thread.Sleep or synchronous I/O — the thread pool runs out of free threads and grows only slowly, so requests queue up and latency spikes even though CPU usage is low. Fix it by going async all the way, removing sync-over-async calls, and using diagnostic tools (dotnet-counters for thread-pool queue length, dotnet-dump).
How do you run work in parallel safely?
For CPU-bound work, use Parallel.ForEach or PLINQ; for I/O-bound concurrency, use Task.WhenAll with a limit (Parallel.ForEachAsync with MaxDegreeOfParallelism, or SemaphoreSlim). Protect shared state with lock, Interlocked or concurrent collections, and pass a CancellationToken everywhere.
await Parallel.ForEachAsync(orderIds, new ParallelOptions { MaxDegreeOfParallelism = 8, CancellationToken = ct },
async (id, token) => await ProcessOrderAsync(id, token));ASP.NET Core and EF Core
Explain the middleware pipeline. Does order matter?
Each middleware can handle the request, call next() to pass it on, and act on the response on the way back. Order matters a great deal: exception handling first, then HTTPS redirection, static files, routing, CORS, authentication before authorisation, then the endpoints. A wrong order produces bugs such as authorisation running without an authenticated user.
How do you make EF Core queries fast?
Project to DTOs with Select, use AsNoTracking() for reads, avoid N+1 with Include or projections, add proper indexes, paginate (keyset pagination for deep pages), use ExecuteUpdate/ExecuteDelete for bulk operations, check the SQL with ToQueryString() and logging, and use compiled queries for very hot paths. More in the LINQ interview questions.
How do you handle configuration and secrets?
Use the options pattern (IOptions<T>, IOptionsMonitor<T>) bound to configuration sections, with validation at startup (ValidateDataAnnotations().ValidateOnStart()). Secrets come from user-secrets in development and from Key Vault, AWS Secrets Manager or environment variables in production — never appsettings.json in git.
How do you build resilient HTTP calls to other services?
Use IHttpClientFactory (to avoid socket exhaustion), with timeouts, retries with exponential backoff and jitter for transient errors only, circuit breakers and fallbacks — through Microsoft.Extensions.Http.Resilience (built on Polly). Make retried operations idempotent.
Design and testing
Which design patterns have you used in .NET projects, and why?
Pick patterns you can defend with an example: Repository / Unit of Work (often unnecessary on top of EF Core — say so), Strategy (pluggable pricing or payment providers), Decorator (adding caching or logging around a service through DI), Mediator/CQRS (separating reads from writes), Outbox (reliably publishing events with database transactions) and Options (configuration).
How do you write testable C# code?
Depend on abstractions injected through constructors, keep business logic free of framework and I/O code, avoid static state and DateTime.Now (inject TimeProvider), and write unit tests with xUnit or NUnit plus Moq or NSubstitute at the boundaries. Add integration tests with WebApplicationFactory and Testcontainers for the database.
public class SubscriptionService(TimeProvider clock, ISubscriptionRepo repo)
{
public async Task<bool> IsActiveAsync(Guid userId)
=> (await repo.GetAsync(userId))?.ExpiresAt > clock.GetUtcNow();
}Scenario questions
- "Memory grows steadily in our API. How do you investigate?" —
dotnet-counters, thendotnet-gcdumpordotnet-dump, compare heaps, look for static caches, event-handler leaks and undisposed objects - "An endpoint is slow only in production." — check traces (OpenTelemetry), database plans, thread-pool starvation, external dependencies, and data volume compared with test environments
- "How would you split a monolith?" — find bounded contexts, extract behind an interface first, use the outbox pattern and events, and use the strangler-fig approach with routing
Revise the C# interview questions, .NET Core questions and ASP.NET questions, then take the C# quiz.