Skip to content
Sharp

Delegates & events interview questions

Func, Action, multicast delegates, events, closures.

3 questions with answers and explanations · 2 flashcards

Key ideas

  • A delegate is a type-safe reference to a method. Func<..., TResult> returns a value; Action<...> doesn't; Predicate<T> returns bool.
  • Delegates are multicast: += adds to the invocation list.
  • An event restricts outside code to +=/-=. Only the declaring class can raise it.
  • Lambdas capture variables, not values. A for loop variable is shared across iterations.

Questions

  1. What does declaring a delegate member with the event keyword add over a public delegate field?Multiple choiceMedium
  2. What does this program print?What does this code output?Hard
  3. Name a built-in generic delegate type for a method that takes an int and returns a bool.Fill in the blankMedium