C#.NET — Which of the following is a necessary condition for implementing delegates?

Difficulty: Easy

Correct Answer: Compile-time polymorphism

Explanation:


Introduction / Context:
Delegates in C# act as type-safe function pointers. Understanding what condition is needed for delegates helps clarify their design principles in the .NET runtime.



Given Data / Assumptions:

  • Delegates must match method signatures at compile-time.
  • Delegates enforce type safety.


Concept / Approach:
Delegates rely on compile-time polymorphism (static binding of method signatures) to ensure that assigned methods match their declared signature. Unlike inheritance or runtime polymorphism, delegates work by creating callable objects bound to methods that satisfy the signature contract.



Step-by-Step Solution:

Check A: Class declaration — Not mandatory; delegates are standalone types. Check B: Inheritance — Not needed for delegates to work. Check C: Run-time polymorphism — Delegates don’t rely on virtual/override mechanisms. Check D: Exceptions — Unrelated to delegates. Check E: Compile-time polymorphism — Correct; ensures method signature compliance.


Verification / Alternative check:
Try assigning a method with mismatched signature to a delegate; compiler error confirms compile-time enforcement.



Why Other Options Are Wrong:
They introduce unrelated concepts (inheritance, exceptions, runtime polymorphism).



Common Pitfalls:
Confusing delegate type-safety with runtime polymorphism. Delegates are strongly checked at compile-time.



Final Answer:
Compile-time polymorphism

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion