O'Reilly logo

.NET Common Language Runtime Unleashed by Kevin Burton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required