delegate Basics

A delegate is similar to a COM (or a C# interface for that matter) interface in that a COM interface specifies a contract between the implementer and the user. A COM interface was abstract and could not be instantiated. Its importance was the contract that it specified. A delegate is similar, but it only specifies a contract for a single function call.

To create a delegate, you first need to define what the delegate is to look like—in other words, define a delegate type. The code snippet in Listing 14.1 begins a simple HelloWorld sample with a delegate definition. The full source for the code in Listings 14.114.8 is in the HelloWorld directory.

Listing 14.1. Defining a delegate Type
 public delegate void HelloWorldDelegate(string ...

Get .NET Common Language Runtime 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.