Lecture overview -- Keyboard shortcut: 'u'  Previous page: Delegates that contain instance methods -- Keyboard shortcut: 'p'  Next page: Lambda Expressions -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 9 : 20
Object-oriented Programming in C#
Operators, Delegates, and Events
Multivalued delegates

A delegate can contain more than one method.

A delegate can contain an arbitrary number of methods

/user/normark/oop-csharp-1/sources/c-sharp/delegates/4/Messenger.csInstall and UnInstall message methods in the Messenger class. This program is explained

Similar to class Messenger on the previous page. Allows adding and subtraction of methods to the delegate in a Messenger object via the methods InstallMessage and UninstallMessage.

/user/normark/oop-csharp-1/sources/c-sharp/delegates/4/a.csA simple class A. This program is explained

Identical to class A on the previous page. Just a simple class with an instance method.

/user/normark/oop-csharp-1/sources/c-sharp/delegates/4/application.csAn Application class. This program is explained

Illustrates that it is possible to add (and delete) a number of different methods (of same signature) to a given instance of class Messenger.

/user/normark/oop-csharp-1/sources/c-sharp/delegates/4/outputOutput from Main of class Application.

Confirms that a delegate calls all of its methods.

Summary of delegates

Delegates are types. The values of delegate types are methods

With delegates, methods become first class citizens

A variable of a delegate type can contain both static and instance methods

A variable of a delegate type can even contain two or more methods

Read more about multivalued delegates in the text book version of this material.