1325 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.
Extract method and class, replace conditional with polymorphism, introduce parameter object, simplify conditionals, remove dead code and break dependencies safely under tests.
Defines refactoring as behaviour-preserving structural change, separates it from rewrites, fixes and features, and explains why tests (or characterisation tests) and small committed steps make it safe.
Walks through Extract Method and Extract Class on an order service, how Roslyn-based IDE refactorings handle parameters, return values and references, and the cases (out parameters, async, reflection, captured state) where they still change behaviour.
Refactors a long-parameter, deeply nested invoice method using Introduce Parameter Object (a record), guard clauses and switch expressions, and covers the traps: changed validation order, bag-of-everything parameter objects, boolean flags and non-exhaustive switches.
Applies Replace Conditional with Polymorphism to an invoice type code repeated across methods, compares subclasses, a dictionary of strategies and switch expressions, and covers the expression problem, EF Core inheritance mapping and when to keep the switch.
Covers finding dead code with compiler and IDE analysers (IDE0051, IDE0052, IDE0060), solution-wide analysis, coverage and production telemetry, removing stale feature flags, and a safe deletion process with tombstones and small reversible PRs.
Demonstrates dependency-breaking techniques on a legacy order service: TimeProvider and FakeTimeProvider for the clock, wrapping statics behind an instance, extracting a data-access dependency, adapting a sealed SDK client, and choosing between object seams, constructor parameterisation and integration tests.
A real-world plan for refactoring a critical payment allocation module during ongoing feature work: characterisation and golden-master tests, branch by abstraction, small trunk-based PRs, shadow (parallel) runs comparing old and new results, flag-controlled cut-over and coordination with other teams.