What is .Net Delegates

Delegates in C#

In the .NET environment, a delegate is a type that defines a method signature and it can pass a function as a parameter. In simple words we can say delegate is a .NET object which points to a method that matches its specific signature. A delegate is a form of type-safe function pointer used by the Common Language Infrastructure.


You create a delegate with the delegate keyword, followed by a return type and the signature of the methods that can be delegated to it.

A delegate is independent of the type of method that it references. The signature of the method and the delegate should match. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.


There are two types of Delegates

1) Singlecast delegates

2) Multiplecast delegates

Singlecast delegate:

A Singlecast delegate point to single method at a time and it is derived from System.Delegate class.

Multicast Delegate:

A delegate that can have more than one element in its invocation list is known as a multicast delegate. When you create a Delegate object, you actually create an instance of an object that inherits the System.MulticastDelegate class. The MulticastDelegate class lets you assign multiple methods to a delegate.

What is the use of delegates in C#

The following examples shows how to implement delegates in .Net programs

C# Delegate

VB.Net Delegate

Differences between events and delegates

Delegate and Event concepts are completely tied together. Even if they were exactly the same thing there will still remain the semantical difference. Delegates is a function pointer which can able to store the address of any function with same prototype. While Event is a function handler which can handles or run the functions in same prototype of its delegate. More.... Events and Delegates
 (C) 2022    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About