The book Illustrated C# 7, Fifth Edition by Daniel Solis and Cal Schrotenboer published by Apress shows the steps involved in using a delegate, and illustrates that they are very similar to the steps you use to work with custom classes.
As the book says on page 350: “A delegate is a user-defined type, just as a class is a user-defined type. But whereas a class represents a collection of data and methods, a delegate holds one or more methods and a set of predefined operations.”
- Declare a delegate type. A delegate declaration looks like a method declaration, except that it doesn’t have an implementation block.
- Declare a delegate variable of the delegate type.
- Create an object of the delegate type and assign it to the delegate variable. The new delegate object includes a reference to a method that must have the same signature and return type as the delegate type defined in the first step.
- You can optionally add additional methods into the delegate object. These methods must have the same signature and return type as the delegate type defined in the first step.
- Throughout your code you can then invoke the delegate, just as it if it were a method. When you invoke the delegate, each of the methods it contains is executed.