CHAPTER 10 DELEGATES, EVENTS, AND LAMBDA EXPRESSIONS
This time, the compiler-generated class breaks down as follows:
sealed class MyDelegate : System.MulticastDelegate
{
public string Invoke(bool a, bool b, bool c);
public IAsyncResult BeginInvoke(bool a, bool b, bool c,
AsyncCallback cb, object state);
public string EndInvoke(IAsyncResult result);
}
Delegates can also “point to” methods that contain any number of out or ref parameters (as well as
array parameters marked with the params keyword). For example, assume the following delegate type:
public delegate string MyOtherDelegate(out bool a, ref bool b, int c);
The signatures of the Invoke() and BeginInvoke() methods look as you would expect; however,
check out the EndInvoke() method, which now includes the set of all out/ref arguments defined by the
delegate type:
public sealed class MyOtherDelegate : System.MulticastDelegate
{
public string Invoke(out bool a, ref bool b, int c);
public IAsyncResult BeginInvoke(out bool a, ref bool b, int c,
AsyncCallback cb, object state);
public string EndInvoke(out bool a, ref bool b, IAsyncResult result);
}
To summarize, a C# delegate type definition results in a sealed class with three compiler-generated
methods whose parameter and return types are based on the delegate’s declaration. The following
pseudo-code approximates the basic pattern:
// This is only pseudo-code!
public sealed class DelegateName : System.MulticastDelegate
{
public delegateReturnValu R