Working with Delegates

Delegates let you pass methods as parameters. They provide you with another form of polymorphism, because you can assign methods to delegates at runtime, leaving the rest of your code unchanged but calling the methods you specify at runtime. You declare a delegate like this:

[attributes] [modifiers] delegate result-type identifier ([formal-parameters]);

Here are the parts of this statement:

  • attributes (Optional)— Hold additional declarative information, as we'll see in Chapter 14.

  • modifiers (Optional)— The allowed modifiers are new and a valid combination of the four access modifiers.

  • result-type The result type, which matches the return type of the method.

  • identifier The delegate name.

  • formal-parameters (Optional)— ...

Get Microsoft® Visual C#® .NET 2003 Kick Start now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.