O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

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

14.1. What are delegates?

Think of a delegate as a special type – something like a class. [2] A delegate type is a class type that is derived from System.Delegate. When you declare a delegate using the delegate keyword, you do not have to specify that you are deriving from System.Delegate; that is implicit.

[2] A note for C++ developers: C# delegates are similar to C++ function pointers. However, unlike function pointers, delegates are object-oriented.

A delegate type's main job is to encapsulate one or more methods (see Figure 14.1). A delegate instance is an instance of a delegate type. You can view delegate instances as representations of methods, so that when you invoke a delegate instance, the method(s) it encapsulates is also invoked.

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