Dear All
Can you give me scenario when we should use Delegates in C#. i have read about delete and know that is hold reference of method .but i have not understand when should i use delegate .
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.
Nilesh JadavPosted Jun 4, 2015, 6:51 AM
http://stackoverflow.com/questions/2019402/when-why-to-use-delegates
Use a delegate in the following circumstances:
An eventing design pattern is used.
It is desirable to encapsulate a static method.
The caller has no need to access other properties, methods, or interfaces on the object implementing the method.
Easy composition is desired.
A class may need more than one implementation of the method.
http://csharpindepth.com/Articles/chapter2/events.aspx
C# - What is Delegates in C# Example | Use of Delegates in C#
Thank you !
Pankaj Kumar ChoudharyPosted Jun 4, 2015, 5:59 AM
When you want to provide a function, that will be executed on some event. You give to the event's Event handler a delegate of a function that is about to be executed. They are great when you do event driven programming.
Also when you have functions that have functions as arguments (LINQ expressions, predicates, map-functions, aggregate functions, etc). This functions are generally called higher level functions.
In addition you can wrap some functionality, when the caller has no need access other properties, methods, or interfaces on the object implementing the method. In this case it replaces inheritance, somehow.
Rajeesh MenothPosted Jun 4, 2015, 5:35 AM