C#.NET — Delegates: Identify the incorrect statement.
-
ADelegates are reference types.
-
BDelegates are object oriented.
-
CDelegates are type-safe.
-
DDelegates serve the same purpose as function pointers in C and pointers to member function operators in C++.
-
EOnly one method can be called using a delegate.
Answer
Correct Answer: Only one method can be called using a delegate.
Explanation
Introduction / Context:This question tests fundamental knowledge about delegates in C#. Delegates are central to implementing callbacks and events, and it is important to differentiate their capabilities from older language constructs like function pointers.
Given Data / Assumptions:
- Delegates are reference types and part of the object-oriented nature of C#.
- They are strongly type-safe, enforcing matching signatures.
- They allow multicasting.
Concept / Approach:The false statement among the options is that only one method can be bound to a delegate. In fact, C# supports multicast delegates, which can call multiple methods in an invocation list.
Step-by-Step Solution:
A — True: delegates are reference types. B — True: delegates fit within the object-oriented paradigm of C#. C — True: they are type-safe; the method signature must match the delegate signature. D — True: they serve a role similar to function pointers in unmanaged languages. E — False: delegates can point to multiple methods, making them multicast.Verification / Alternative check:Create a delegate and use += to attach multiple methods. All methods execute in sequence when invoked, proving the incorrectness of option E.
Why Other Options Are Wrong:All others accurately describe delegates. Only E contradicts the multicast feature.
Common Pitfalls:Assuming delegates work exactly like C pointers; forgetting multicast behavior.
Final Answer:Only one method can be called using a delegate.