Delegates

Interfaces facilitate writing code so that your program can be called into by some other code. This style of programming has been available for a long time, under the guise of “callback” functions. In this section we examine delegates in VB.NET, which can be thought of as type-safe and object-oriented callback functions. Delegates are the foundation for a design pattern, known as events, which we'll look at in the next section.

A callback function is one which your program specifies and “registers” in some way, and which then gets called by other code. In C and C++ callback functions are implemented using function pointers.

In VB.NET you can encapsulate a reference to a method as a delegate object. A delegate can refer to either a static ...

Get Application Development Using Visual Basic® and .NET now with O’Reilly online learning.

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