Aug 21

Combine Two Delegates C#-Example

Combine Two Delegates C#

A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. 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.

A delegate can define its own type parameters. The generic delegate can specify the type argument to create a closed constructed type. The multicast delegate consists of a list of the assigned delegates. When the multicast delegate is called, it invokes the other delegates in the list in order. Only delegates of the same type can be combined.

Below is a C# Program to Combine Two Delegates. Here When the multicast delegate is called, it invokes the delegates in the list, in order.

Below is the Output :

Permanent link to this article:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.