📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

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.

Refactoring

Extract method and class, replace conditional with polymorphism, introduce parameter object, simplify conditionals, remove dead code and break dependencies safely under tests.

  1. What is refactoring, and what isn't it? Why do you need tests before you start, and how do you keep a refactoring safe while you work?

    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.

    Junior Theory Refactoring Β· πŸ”— 2 follow-ups
  2. Show me extract method and extract class on a real C# example. How do the IDE refactorings in Visual Studio and Rider do it safely, and what can still go wrong?

    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.

    Intermediate Coding Refactoring Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  3. A CreateInvoice method takes nine parameters and its body is nested five levels deep in if statements. How would you refactor it with introduce parameter object, guard clauses and pattern matching, and what traps should you avoid?

    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.

    Intermediate Coding Refactoring Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  4. An Invoice class switches on its Kind in five different methods. How would you replace the type code with polymorphism, when is a dictionary of strategies or a single switch expression the better choice, and when should you leave the conditional alone?

    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.

    Mid-Level Coding Refactoring Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  5. How do you find and remove dead code in a large .NET codebase with confidence? Explain what analysers, code coverage, production telemetry and feature flags each tell you, and how you delete safely.

    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.

    Mid-Level Theory Refactoring Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  6. Show me in code how you break the dependencies that stop a legacy OrderService from being unit tested: DateTime.Now, a static helper, new SqlConnection inside a method and a sealed third-party client. Which seams and techniques would you use, and how does TimeProvider help?

    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.

    Senior Coding Refactoring Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  7. You need to refactor the payment allocation module that every invoice flows through, while two other teams keep shipping features in it. Walk me through how you would do it: the plan, the safety nets, how you keep PRs small and how you know it's safe to switch over.

    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.

    Senior RealWorldScenario Refactoring Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me