Delgates are similar to a function pointer in C language.
A delegate is an object which stores the reference/address of a function.
A delegate can hold the reference of only those functions whose signature matches with that of a function.
Syntax:
<accessModifier> delegate <datatype> <nameofdelegate>(<arg1>,<arg2>)
There are 2 types of delegates:
- Unicast delegate
- Multicast delegate
1. Unicast delegate holds the reference of one function.
Example:
- using System;
- namespace unicast
- {
- public delegate int AddDelegate(int x, int y);
- class program
- {
- static void Main()
- {
- AddDelegate dlg = new AddDelegate(Add);
- int r = dlg.Invoke(10, 20);
- Console.WriteLine("Sum is {0}", r);
- Console.ReadKey();
- }
- public static int Add(int x, int y)
- {
- return (x + y);
- }
- }
- }

Sridhar SharmaPosted Jan 4, 2016, 8:12 AM
Nice Share
Santhakumar MunuswamyPosted Dec 31, 2015, 1:46 AM
Thanks for nice share
Dhanik SahniPosted Dec 30, 2015, 4:23 AM
Good share and easy to understand.