Lecture overview -- Keyboard shortcut: 'u'  Previous page: Delegates in C# -- Keyboard shortcut: 'p'  Next page: Multivalued delegates -- 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 8 : 20
Object-oriented Programming in C#
Operators, Delegates, and Events
Delegates that contain instance methods

The methods on the previous page were all static. We will now explain how to deal with instance methods in relation to delegates.

In the examples until now all delegates contained static methods

In the case that delegates contain instance methods, the receiver is part the delegate

/user/normark/oop-csharp-1/sources/c-sharp/delegates/3/Messenger.csA Messenger class and a Message delegate. This program is explained

Class Messenger encapsulates a Message delegate. Via the DoSend method it is possible to activate the method(s) in the encapsulated Message delegate.

/user/normark/oop-csharp-1/sources/c-sharp/delegates/3/a.csA very simple class A with an instance method MethodA. This program is explained

A class A with an instance method MethodA.

/user/normark/oop-csharp-1/sources/c-sharp/delegates/3/application.csAn Application class which accesses an instance method in class A. This program is explained

Illustrates how to deal with an instance method of a particular object as a delegate.

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

Confirms that MethodA in a2 is called.

Read more about delegates with instance methods in the text book version of this material.