📁 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.

Structural Patterns

Adapter, Bridge, Composite, Decorator, Facade, Flyweight and Proxy: wrapping and composing objects in .NET 10, from DelegatingHandler and DI decorators to DispatchProxy.

  1. What is the Adapter pattern? Show how you would wrap a third-party payment SDK behind your own interface, explain object versus class adapters, and say what belongs inside the adapter and what does not.

    Adapter intent, object vs class adapter, wrapping a vendor SDK (Stripe.net) behind a domain interface, translating units, types and exceptions, .NET examples (StreamReader, TaskCompletionSource, Serilog's ILoggerProvider), and keeping business logic out of adapters.

    Junior Theory Structural Patterns Β· πŸ”— 2 follow-ups
  2. What is the Decorator pattern? Explain how it adds behaviour such as caching, logging or retry without changing the original class, where .NET uses it (Stream wrappers, DelegatingHandler), and how you register decorators with the built-in DI container.

    Decorator intent and structure, composition-based stacking, .NET examples (BufferedStream, GZipStream, CryptoStream, DelegatingHandler pipelines), registering decorators with factory delegates, keyed services or Scrutor, ordering, and decorators vs inheritance, middleware and AOP.

    Intermediate Theory Structural Patterns Β· πŸ”— 3 follow-ups
  3. Write a caching decorator for IProductRepository using HybridCache in .NET 10. Register it with the built-in container, then with Scrutor, and explain how you handle invalidation, cache keys, stampedes and the risk of caching errors or other users' data.

    Coding a HybridCache caching decorator: GetOrCreateAsync with keys and TTLs, stampede protection, invalidation on writes (RemoveAsync, tags), not caching nulls or failures by accident, tenant-aware keys, immutable cached types, registration via factory delegate, keyed services and Scrutor, and tests.

    Mid-Level Coding Structural Patterns Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  4. What is the Facade pattern? Give examples from .NET and from a typical business application, and explain how a good facade differs from a 'god service' that does everything.

    Facade intent (a simple entry point over a subsystem), .NET examples (File.ReadAllTextAsync, HttpClient, JsonSerializer, DbContext), an order-checkout facade, facade vs god service vs application service, and keeping facades thin.

    Intermediate Theory Structural Patterns Β· πŸ”— 2 follow-ups
  5. What is the Proxy pattern? Explain virtual, remote and protection proxies, and how EF Core lazy-loading proxies, DispatchProxy and Castle DynamicProxy implement it. What are the risks of proxies you can't see in the code?

    Proxy intent and kinds (virtual, remote, protection, smart reference), EF Core lazy-loading proxies (virtual navigations, Castle, N+1, disposed-context errors), DispatchProxy for interfaces (and its AOT limits), Castle DynamicProxy interceptors, generated HTTP/gRPC clients, and the cost of invisible behaviour.

    Mid-Level Theory Structural Patterns Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  6. What is the Composite pattern? Show how you would model a tree of permissions, pricing rules or menu items so that clients treat single items and groups the same way, where .NET uses it, and how you guard against deep recursion and cycles.

    Composite intent (part-whole trees with a uniform interface), leaf vs composite, a permission-group or rule tree in C#, .NET examples (CompositeFileProvider, CompositeChangeToken, expression trees), recursion depth and StackOverflowException, cycle detection, and storing hierarchies (recursive CTE, hierarchyid).

    Mid-Level Theory Structural Patterns Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  7. What is the Bridge pattern, and what problem does it solve? Use a notifications example (message types × channels) and explain how ILogger/ILoggerProvider and HttpClient/HttpMessageHandler are bridges in .NET. How is Bridge different from Adapter and Strategy?

    Bridge intent (separate an abstraction from its implementation so both vary independently), avoiding M×N class explosions, notification types × channels in C#, ILogger over ILoggerProvider and HttpClient over HttpMessageHandler, and Bridge vs Adapter vs Strategy.

    Mid-Level Theory Structural Patterns Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  8. Adapter, Decorator, Proxy and Facade all wrap something. How do you tell them apart? Compare their intent, interface and typical .NET examples, and explain why the distinction matters in a real codebase.

    A comparison of the four wrapper patterns: Adapter (converts an interface), Decorator (same interface, adds behaviour), Proxy (same interface, controls access and lifecycle), Facade (new simpler interface over many classes), with .NET examples, a decision guide, and why mislabelling leads to misplaced logic such as duplicate retries.

    Mid-Level Theory Structural Patterns Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  9. What is the Flyweight pattern? Explain intrinsic versus extrinsic state, how .NET uses flyweights (string interning, cached instances, SearchValues, frozen collections), when deduplicating objects actually saves memory, and how you would prove the saving with dotnet-gcdump.

    Flyweight intent (share immutable intrinsic state, pass extrinsic state in), string literal interning and string.Intern's process-lifetime cost, custom string pools, cached instances (Task.CompletedTask, Array.Empty, CultureInfo), SearchValues and FrozenDictionary as precomputed shared state, and measuring with dotnet-gcdump and dotnet-counters.

    Senior Theory Structural Patterns Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  10. After a refactor, your API starts caching error responses for an hour, some outgoing calls are retried far more often than configured, and every log line appears twice. You suspect the order of decorators and HttpClient handlers. How do you diagnose and fix it?

    Debugging decorator and DelegatingHandler ordering: fallbacks cached by a cache decorator, timeouts and retries layered in the wrong order or twice (custom handler plus AddStandardResilienceHandler), duplicate logging from double registration; inspecting IServiceCollection descriptors, the resolved decorator chain, handler order, and OpenTelemetry span nesting; tests that lock the order.

    Senior Debugging Structural Patterns Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

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