Delegates
hi
what is delegate in C# and how it is used and why should we use delegates
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.
Lalit MPosted Dec 3, 2009, 12:21 AM
When use of Delegates?
This is a valid question. Before C# 3.0, you could use delegates or declare full methods to bind to events. Now we can declare event directly through lambda. (See this post on many different examples on how to bind event handlers).
Jon Skeet answered me the following:
Delegates is a keyword that can be used to declare inline methods. This inline code can be stored inside variables and then executed when necessary. This is exactly what happens when you are binding methods to events. You are storing the signature of the method inside a variable that will store multiple methods signature and call them when an event is happening.
Of course, it's limiting to think about delegates only as events. If we check the standard definition for the word delegation:
As I already demonstrated inside the StreamProxy class, we can easily give another software the tools to answer it's solution. But sometimes, the call might not be necessary. Just like when you are sending a data repository to a service class to save a model, delegate is basically just sending any method that match the accepted signature instead of complete class.
One of the most recent use of Lambda's inside C# is inside Mocking tools. Moq use those to easily describe expectations, returned values, and so on. This allow Moq to be type safe instead of relying on Reflection and string comparison. This has brought us compile time check rather than runtime check.
There is a lot of use for delegates and they are being used more and more. Lots of languages support some form of delegation (.NET, C++, JAVA, and many more)
Why Use of Delegates? Click HereShow this articles understanding delegates
naveenPosted Sep 2, 2010, 4:40 AM
the link u provided also didn't work
http://www.codersource.net/csharp_delegates_events.html
Plz check out and upload proper one
thanks
naveenPosted Sep 2, 2010, 4:35 AM
i just wanted bring your notice that in your post ,
Why Use of Delegates? Click Here
Click here ,link did not work.Page cannot found ERROR occurs
check with that upload right link
thanks
Rekha SinghPosted Dec 28, 2009, 7:42 AM
in delegates we have to pass the method name as parameter to our delegate
paul danielPosted Dec 23, 2009, 9:25 AM
This link will helpful to u
http://www.codersource.net/csharp_delegates_events.html
Amit ChoudharyPosted Dec 3, 2009, 12:18 AM
You should go to this article http://www.exforsys.com/tutorials/csharp/delegates-in-csharp.html I'm sure all questions regarding Delegates will be answered