Posted by: Rhonda | February 3, 2008

C# Delegates

A Delegate is a type that points to a method. Once a Delegate references a method, it behaves just like that method. This means it can be used like a method which includes parameters and return values. Unlike C++ function pointers, delegates are object-oriented, type safe, and secure.

Some Aspects of Delegates

Similar to C++ function pointers, but are type safe
Can be used to define callback methods
Multiple methods can be called on a single event
Methods are allowed to be passed as parameters

Delegate syntax

public delegate void Del(string message);

Source Code Example (C#)

Source Code Example (VBNET)

Result

result.gif

Related Content
Delegates and Events in C# / .NET
C# Delegates Explained
The dark side of C# Delegates

Happy Programming.


Leave a response

You must be logged in to post a comment.

Categories