/* This example shows how you can use delegates in a generic list to call several methods in sequence
* The final output of this tutorial will be:
* WriteOut method called
* WriteIn method called
* As you see, the methods are called in the order they were added to the generic list.
* Also note that the value of the argument is the same for each call, that's because using this
* method, you are supplying the value seperately to each function in the delegate.
// Declare the delegate to be used later, this sets the return type and expected parameters
// for the delegate. All functions to be included must have the same return type and parameter list.
delegate void myDelegate(int number);
// We'll create a generic array of delegates
List TheDelegates = new List();
// Now we'll add the functions to the delegate array list
// Here we'll loop through every delegate in the list, calling it's associated function
foreach (myDelegate simple in TheDelegates)
// These are the functions to be called by the delegate
void WriteOut(int number)
Console.WriteLine("WriteOut method called");
int i = ++number;
void WriteIn(int number)
Console.WriteLine("WriteIn method called");
int i = --number;