There will be times when you need to pass off, or delegate, the actual execution of a method. In C#, this can be accomplished through delegate types, which store references to methods and can be treated like any other variable. The only caveat is that the delegate itself and any assigned method need to have the same signature—just like integer variables can only hold whole numbers and strings can only hold text.
Basic syntax
Creating a delegate is a mix between writing a function and declaring a variable:
public delegate returnType DelegateName(int param1, string param2);
You start with an access modifier followed the keyword delegate, which identifies it to the compiler as a delegate type. The delegate can have a return type and name like a regular function, as well as parameters if needed. However, this syntax only declares the delegate type itself; in order to use it you need to create an instance like we do with classes...