Delegates
What is the purpose of delegates and an example will help a lot.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 22, 2012, 1:34 AM EST
A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value.
public delegate int PerformCalculation(int x, int y);
Any method that matches the delegate's signature, which consists of the return type and parameters, can be assigned to the delegate. This makes is possible to programmatically change method calls, and also plug new code into existing classes. As long as you know the delegate's signature, you can assign your own delegated method.
Please refer,
http://msdn.microsoft.com/en-us/library/ms173173%28v=vs.80%29.aspx
hope this help.
Chandra Sekhar K160 reputationPosted Feb 22, 2012, 1:54 AM EST
But I have already gone through the link given. But the actual purpose of the delegate is not clear.
1. What is the use of calling a function through another name. In what specific purpose, is it useful.
2. And "A class may need more than one implementation of the method." Need an example supporting this.
The overall thing is - when does the actual use of delegate is used in a real time application.