.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum


Posted By: softraj     Posted Date: September 04, 2009    Points:2   Category :C#
Why delegates are used?

Author: Hefin Dsouza             
Posted Date: September 04, 2009     Points: 5   

Delegates are similar to pointers for Methods.
They are types that references to methods.
The delegate once initialised or assigned to a method starts behaving like the method itself.

The delegate can be also used to reference multiple methods.
Example :

public class Demo
public delegate int Calc(int a,int b);

static void Main()
Calc x=new Calc(Add);
x+=new Calc(Sub);

static int Add(int a,int b)
return a+b;
static int Sub(int a,int b)
return a-b;

Will call both Add and Subtract by just a single call to x(object of the delegate Calc).

Hefin Dsouza

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend