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

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: Neet_Aarzoo             
Posted Date: November 05, 2009     Points: 5   

Delegates are similar to pointer.
They are used to save memory.

Check this code.

Delegates are holding one or multiple function address.The delegate designed using pointers so the delegates are unsafe code from the .Net framework.The delegates are reference types.Depending upon the function prototype we have to declare the delegates.Delegates are of two types

1>Single Cast Delegate.
2>Multi Cast Delegate.

Multi Cast Delegate:
The multi Cast delegate refers multiple single cast delegate.

Example on multicast delegate:

public delegate void dname();
class DelegateDemo
public void m1()
MessageBox.Show("From m1");
public void m2()
MessageBox.Show("From m2");

private void button1_Click(object sender, EventArgs e)
DelegateDemo obj = new DelegateDemo();
dname d1 = new dname(obj.m1);
dname d2 = new dname(obj.m2);
dname d3;
d3 = d1 + d2;


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