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

πŸ“š .NET Interview Questions

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

Delegates and Events

Delegates, multicast delegates, events and event handlers, Func, Action and Predicate, anonymous methods and lambdas.

  1. What is a delegate in C#? Explain what a delegate object contains, how it is created and invoked, delegate equality, how instance and static method targets differ, what allocations happen, and how delegates compare with interfaces and function pointers.

    Delegates as type-safe method references: anatomy (target plus method), creation and invocation, allocation and caching, equality, and choosing delegates versus interfaces or function pointers.

    Junior Theory Delegates and Events Β· πŸ”— 3 follow-ups
  2. What is a multicast delegate? Explain how += and -= build the invocation list, the order handlers run in, what happens to return values and exceptions, why delegates are thread-safe to read but events need care, and how GetInvocationList helps.

    Multicast delegates: Delegate.Combine and Remove, immutable invocation lists, return values, exceptions stopping the chain, thread safety and invoking handlers individually.

    Mid-Level Theory Delegates and Events Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  3. What is an event in C#, and how is it different from a public delegate field? Explain what the event keyword generates, field-like events versus custom add/remove accessors, how to raise an event safely, and static events.

    Events as an encapsulated publish/subscribe mechanism: compiler-generated add/remove, thread-safe subscription, raising safely, custom accessors and the risks of static events.

    Mid-Level Theory Delegates and Events Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  4. How should you design and handle events with EventHandler and EventHandler<TEventArgs>? Explain the sender and EventArgs conventions, async event handlers, and how event subscriptions cause memory leaks, including how you would find and fix one.

    Event handler conventions (sender, EventArgs, EventArgs.Empty, OnXxx), async void handlers, and diagnosing and preventing event-subscription memory leaks with dotnet-dump and weak events.

    Senior Debugging Delegates and Events Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  5. What are Func, Action and Predicate in .NET? When do you use each, why can a Func<T, bool> not be passed where a Predicate<T> is expected, and when would you declare your own delegate type instead?

    The built-in generic delegates Func, Action and Predicate: signatures, variance, where the BCL uses each, delegate type incompatibility and choosing custom delegates or expression trees.

    Junior Theory Delegates and Events Β· πŸ”— 2 follow-ups
  6. What are anonymous methods in C# (the delegate keyword syntax)? How do they differ from lambdas, what can they still do that lambdas cannot, can they be static, and would you use them in new code?

    C# 2 anonymous methods: syntax, captured variables, omitting the parameter list, static anonymous methods, the lack of expression-tree conversion, and how they compare with lambdas.

    Intermediate Theory Delegates and Events Β· πŸ”— 2 follow-ups
  7. How do lambda expressions work in C#? Explain expression versus statement lambdas, natural types, static lambdas, attributes, explicit return types, default parameters (C# 12), parameter modifiers without types (C# 14), and how lambdas compile into closures.

    Lambdas in C# 14: syntax forms, conversion to delegates or expression trees, natural type inference, modern features, closure compilation and allocation cost.

    Mid-Level Theory Delegates and Events Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

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