Questions d'entretien : .NET Developer
100 vraies questions avec réponses modèles et explications pour les candidats Développeur .NET.
Voir un exemple de CV : .NET Developer →S'entraîner avec des cartes
Répétition espacée · Hunter Pass
Questions
Deferred execution means a LINQ query usually runs only when its results are enumerated.
- Operators such as Where and Select build a pipeline without reading the source immediately.
- Each enumeration can run the pipeline again and observe changes made to the source.
- Materializers such as ToList, ToArray, and ToDictionary execute the query and store a snapshot.
Pourquoi cette question est posée: The interviewer is checking whether the candidate can distinguish query construction from query execution.
IEnumerable<T> executes delegates over objects, while IQueryable<T> represents an expression tree for a query provider.
- Enumerable operators invoke compiled delegates in .NET as elements are enumerated.
- An IQueryable<T> provider can translate supported expressions into SQL or another remote query language.
- Crossing to AsEnumerable stops provider translation, so later filtering happens in memory.
Pourquoi cette question est posée: The interviewer is evaluating whether the candidate understands where LINQ work is executed and why that boundary matters.
An IQueryable provider can translate only expression-tree nodes and methods it explicitly supports.
- The lambda is captured as data describing operations rather than compiled directly as a delegate.
- Arbitrary application methods have no automatic equivalent in SQL or another provider language.
- Unsupported expressions should be rewritten, mapped to provider functions, or evaluated only after an explicit in-memory boundary.
Pourquoi cette question est posée: The interviewer is testing knowledge of expression trees and provider translation limits.
Streaming operators can yield results incrementally, while buffering operators must consume some or all input first.
- Where and Select can usually produce each item as soon as they receive it.
- OrderBy must read and sort the full input before yielding its first result.
- Buffering affects memory use and the time until the first result becomes available.
Pourquoi cette question est posée: The interviewer is checking whether the candidate can reason about LINQ memory and latency characteristics.
Multiple enumeration can repeat the underlying work and may produce different results.
- A database-backed or file-backed sequence can perform I/O again for every pass.
- A stateful or changing source may return a different set on the next enumeration.
- Materialize once when a stable snapshot or repeated traversal is actually required.
Pourquoi cette question est posée: The interviewer is evaluating awareness of hidden cost and changing semantics behind an enumerable abstraction.
SelectMany projects each source element to a sequence and flattens those sequences into one result.
- Select preserves nesting, so selecting child collections produces a sequence of collections.
- SelectMany emits the children as one sequence and can retain the parent through its result selector.
- It corresponds conceptually to nested iteration and often to a join-like expansion in query providers.
Pourquoi cette question est posée: The interviewer is checking whether the candidate understands flattening rather than merely memorizing LINQ method names.
Any() answers existence and can stop at the first element, while Count() computes a total.
- For an enumerable without a cheap count, Count() may traverse the entire sequence.
- Query providers commonly translate Any() to an existence check and Count() to an aggregate.
- Use Count() only when the number itself is needed, not as a substitute for existence.
Pourquoi cette question est posée: The interviewer is testing whether the candidate chooses LINQ operators according to semantics and execution cost.
GroupBy semantics are consistent in intent, but provider translation and result shape can differ from LINQ to Objects.
- In memory, GroupBy creates group objects that can be enumerated with all their elements.
- A database provider most reliably translates grouping when each group is reduced with aggregates such as Count or Sum.
- Materializing full groups may require additional shaping or client-side work, so generated queries must be understood.
Pourquoi cette question est posée: The interviewer is evaluating whether the candidate recognizes that identical LINQ syntax can have provider-specific execution behavior.
The compiler rewrites an async method into a state machine that can suspend and resume around incomplete awaits.
- Locals needed after an await become fields of the generated state machine.
- If an awaited operation is already complete, execution may continue synchronously without suspension.
- The method returns a task-like object that represents completion, result, or failure.
Pourquoi cette question est posée: The interviewer is checking for a mental model deeper than saying that await creates another thread.
Async and await do not inherently create a new thread.
- For asynchronous I/O, the thread returns to the pool while the operating system or runtime waits for completion.
- The continuation is scheduled when the operation completes and may run on a thread-pool thread or captured context.
- CPU-bound work needs explicit parallel execution such as Task.Run when offloading is appropriate.
Pourquoi cette question est posée: The interviewer is testing whether the candidate distinguishes asynchronous waiting from parallel CPU execution.
ConfigureAwait(false) tells an await not to require resuming on the captured context.
- It matters with a custom SynchronizationContext or non-default TaskScheduler, as found in classic UI applications and older ASP.NET.
- ASP.NET Core normally has no request synchronization context, so it often makes no observable difference there.
- Library code may use it to avoid unnecessary context coupling, but it does not make the operation itself faster or parallel.
Pourquoi cette question est posée: The interviewer is checking whether the candidate understands continuation context without applying ConfigureAwait as a ritual.
A cancellable operation should accept a CancellationToken and pass it through every cancellable dependency.
- Cancellation is cooperative, so code must observe the token or call APIs that observe it.
- ThrowIfCancellationRequested produces OperationCanceledException and preserves standard task cancellation semantics.
- A token signals a request rather than forcibly stopping work, and cleanup still remains the operation's responsibility.
Pourquoi cette question est posée: The interviewer is evaluating whether the candidate treats cancellation as an end-to-end contract.
ValueTask is useful only when avoiding a Task allocation on frequently synchronous completion provides measured value.
- Task is simpler, supports repeated awaiting, and should remain the default return type.
- A ValueTask must normally be awaited once or converted to a Task before reuse or composition.
- ValueTask has a larger value representation and extra usage rules, so it can cost more when completion is usually asynchronous.
Pourquoi cette question est posée: The interviewer is checking whether the candidate understands ValueTask trade-offs rather than treating it as a faster Task.
Blocking can deadlock when the caller holds a context that the awaited continuation needs in order to resume.
- The caller blocks its context thread while Result or Wait waits for task completion.
- The continuation is queued back to that same context and cannot run because the thread is blocked.
- Async all the way avoids this cycle, while ConfigureAwait(false) can remove context capture in suitable library code.
Pourquoi cette question est posée: The interviewer is testing whether the candidate can explain the dependency cycle behind async deadlocks.
Async void should be reserved for event handlers because callers cannot await or compose it.
- Exceptions escape to the current synchronization context instead of being stored in a returned Task.
- The caller cannot know when the operation completes or cancel it through a task-based contract.
- Returning Task makes completion, failure, testing, and composition explicit.
Pourquoi cette question est posée: The interviewer is checking whether the candidate understands the observable contract of asynchronous methods.
Task.WhenAll creates a task that completes after every supplied task has completed.
- WhenAll does not start operations or create threads; it only observes and coordinates the supplied tasks.
- Awaiting the combined task propagates failure, while the combined task retains all inner exceptions for inspection.
- If no task faults but at least one is canceled, the combined task ends in the canceled state.
Pourquoi cette question est posée: The interviewer is evaluating knowledge of task composition and aggregate completion semantics.
An exception from an async Task-returning method is stored in the returned task and rethrown when it is awaited.
- Exceptions before and after an incomplete await both become task failure once execution is inside the async method.
- Await rethrows the failure without wrapping it in AggregateException in normal use.
- A task that is never awaited or otherwise observed can hide failure from the calling flow.
Pourquoi cette question est posée: The interviewer is checking whether the candidate understands how asynchronous failures cross method boundaries.
IAsyncEnumerable<T> streams elements asynchronously, while Task<IEnumerable<T>> asynchronously produces a complete enumerable.
- await foreach can wait between elements without buffering the entire result first.
- A Task<IEnumerable<T>> normally signals that collection setup or materialization finishes before enumeration starts.
- Cancellation can be supplied to asynchronous enumeration with WithCancellation or an enumerator cancellation token.
Pourquoi cette question est posée: The interviewer is testing whether the candidate can distinguish asynchronous streaming from asynchronous batch retrieval.
TaskCompletionSource<T> exposes a Task whose completion is controlled explicitly by other code.
- It adapts callbacks, events, or external completion signals to the task-based asynchronous model.
- SetResult, SetException, and SetCanceled determine the final state, while TrySet variants handle races safely.
- RunContinuationsAsynchronously can prevent continuations from running inline inside the code that completes the source.
Pourquoi cette question est posée: The interviewer is evaluating whether the candidate understands how non-task APIs are bridged into task-based code.
A delegate is a type-safe object that references a method with a compatible signature.
- It can reference static or instance methods and can be passed as data.
- Multicast delegates maintain an invocation list and call each target in order.
- Func, Action, and Predicate are common generic delegate types for values, procedures, and conditions.
Pourquoi cette question est posée: The interviewer is checking whether the candidate understands delegates as typed behavior rather than merely callback syntax.
Questions verrouillées
- 21
How do C# events differ from public delegate fields?
delegatesdelegation - 22
What does a lambda expression capture?
lambdadelegates - 23
How does multicast delegate invocation handle return values and exceptions?
error-handlingdelegatesdelegation - 24
What is the difference between a lambda converted to a delegate and one converted to an expression tree?
lambdadelegatesdelegation - 25
Why should event subscribers often unsubscribe?
delegates - 26
What are generic constraints used for in C#?
generics - 27
How does the new() generic constraint work?
generics - 28
Which types satisfy the unmanaged constraint, and what guarantee does it provide?
- 29
What are covariance and contravariance in C# generics?
generics - 30
What are static abstract interface members useful for in generic code?
genericstypes - 31
What contract does IDisposable represent?
resource-management - 32
How does a using statement work with IDisposable?
resource-management - 33
When is IAsyncDisposable needed?
- 34
How does the generational garbage collector in .NET work?
gc - 35
What is a finalizer and why should it be rare?
- 36
What is the Large Object Heap in .NET?
data-structures - 37
What problem does dependency injection solve?
injectiondependenciesdependency-injection - 38
What do transient, scoped, and singleton lifetimes mean in ASP.NET Core DI?
aspnet - 39
Why is constructor injection generally preferred?
injection - 40
How can scoped services be used from a singleton or background service?
- 41
What does change tracking do in Entity Framework Core?
orm - 42
How do AsNoTracking and AsNoTrackingWithIdentityResolution differ?
- 43
What is an EF Core migration?
migrationsorm - 44
What is the role and intended lifetime of DbContext?
orm - 45
How does the ASP.NET Core middleware pipeline work?
middlewareaspnetci-cd - 46
What is the difference between middleware and endpoint filters in ASP.NET Core?
middlewareaspnetendpoints - 47
What are the main capabilities and limits of the built-in ASP.NET Core DI container?
aspnetcontainers - 48
How do records differ from ordinary classes in C#?
records - 49
What capabilities does pattern matching provide in modern C#?
pattern-matching - 50
How do Span<T> and Memory<T> differ?
memory - 51
How would you implement a new ASP.NET Core endpoint that creates an order?
aspnetendpoints - 52
How do you choose the order of middleware in an ASP.NET Core pipeline?
middlewareaspnetci-cd - 53
How would you implement consistent exception responses across an ASP.NET Core API?
aspnetapierror-handling - 54
When would you implement cross-cutting behavior as middleware rather than an MVC filter?
middlewareaspnet - 55
How would you add a correlation ID to every API request and response?
correlationapi - 56
How would you return validation errors consistently from an ASP.NET Core API?
validationapiaspnet - 57
How would you make a payment POST endpoint safe to retry?
resilienceendpoints - 58
How would you add pagination to an ASP.NET Core list endpoint?
endpointspaginationaspnet - 59
How would you evolve a public ASP.NET Core API without breaking existing clients?
aspnetapi - 60
How would you enforce authorization for an order endpoint owned by the current user?
authendpoints - 61
How would you diagnose a deadlock caused by mixing async code with .Result or .Wait()?
asynclocking - 62
How do you decide whether to use ConfigureAwait(false) in .NET code?
configasync - 63
How would you find and fix a forgotten await in an ASP.NET Core request?
asyncaspnet - 64
How would you fix an async void method used outside an event handler?
asyncdelegates - 65
How would you run several independent I/O operations concurrently without overwhelming a dependency?
dependenciesconcurrency - 66
How would you add cancellation to a long-running API operation?
resilienceapi - 67
When would you use Task.Run in an ASP.NET Core application?
aspnetasync - 68
How would you investigate thread-pool starvation in an ASP.NET Core service?
aspnetconcurrency - 69
How would you fix a race caused by multiple Tasks updating shared state?
- 70
How would you avoid leaking an IAsyncDisposable resource in asynchronous code?
async - 71
How would you identify and remove an N+1 query problem in EF Core?
queriesn+1orm - 72
When would you apply AsNoTracking to an EF Core query?
queriesorm - 73
How would you optimize an EF Core query that loads full entities but returns only three fields?
queriesormoptimization - 74
How would you fix a large EF Core Include query that creates a Cartesian explosion?
queriesorm - 75
How would you deploy an EF Core migration safely during a rolling release?
migrationsormdeployment - 76
How would you handle two users editing the same EF Core entity?
orm - 77
How would you make several EF Core writes atomic?
ormconcurrency - 78
How would you fix an EF Core query that cannot be translated to SQL?
sqlqueriesorm - 79
How would you implement stable pagination in an EF Core query?
queriesormpagination - 80
How would you fix errors caused by using one DbContext from parallel Tasks?
orm - 81
How would you approach a report that an ASP.NET Core endpoint is slow?
aspnetendpoints - 82
How would you reduce excessive allocations in a hot C# path?
- 83
How would you return a very large result without buffering it all in memory?
memory - 84
How would you add caching to a frequently read ASP.NET Core endpoint?
aspnetendpointscaching - 85
How would you verify that a C# optimization actually improves performance?
optimization - 86
How would you choose between transient, scoped, and singleton lifetimes in ASP.NET Core DI?
aspnet - 87
How would you fix a singleton service that depends on a scoped DbContext?
orm - 88
How would you remove service locator usage from application code?
locators - 89
How would you inject one of several payment provider implementations?
- 90
How would you resolve a circular dependency reported by the DI container?
containersdependencies - 91
How would you unit test an application service with xUnit and Moq?
unit - 92
How would you integration test an ASP.NET Core endpoint?
aspnetendpointsintegration - 93
How would you fix a brittle Moq test that verifies every internal call?
- 94
How would you write a reliable xUnit test for an asynchronous method?
unitasync - 95
How would you test EF Core query behavior accurately?
queriesorm - 96
How would you test custom middleware that changes responses?
middlewareaspnet - 97
How would you make code that depends on current time easy to test?
- 98
How would you fix xUnit tests that fail only when run in parallel?
unit - 99
How would you protect a critical endpoint from a known performance regression?
endpoints - 100
How would you take ownership of an ASP.NET Core feature from design through release?
designaspnetownership