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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.