Delegates
What is the purpose of delegates and an example will help a lot.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Chandra Sekhar KPosted Feb 22, 2012, 6:54 AM
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.
Jignesh TrivediPosted Feb 22, 2012, 6:34 AM
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.