Understanding Delegates

Delegates are type-safe function pointers. The main difference between classic function pointers (such as C++ pointers) and delegates is that function pointers can point anywhere, which can be dangerous. Delegates, on the other hand, can point only to those methods that respect delegates’ signatures. Delegates hold a reference to a procedure (its address) and enable applications to invoke different methods at runtime, but such methods must adhere to the delegate signature. Delegates also enable you to invoke a method from another object. This is important according to the main purpose of delegates, which is offering an infrastructure for handling events.

Where are Delegates Used?

Delegates are used in event-handling ...

Get Visual Basic 2015 Unleashed 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.