Chapter 20

Answers to Chapter 20 Review Questions

1: What are the similarities and differences between delegates and abstract methods?
A1: Similarities:
  • They both specify a return type and parameters for a method that they are able to represent and invoke at runtime.

  • They both allow you to postpone the decision of which method to invoke until runtime.

Differences:

  • The method name must match that of the abstract class. The method name is irrelevant for the delegate.

  • Abstract methods work through inheritance, interfaces, and dynamic binding.

  • Generally, delegates are more suited for event handling purposes.

2: Why is delegate a good name for the delegate construct?
A2: A delegate is called like a method, but unlike the method, it does not execute the ...

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.