+ 1

Why do we need delegates

so as much as I know delegate is a pointer to a function so why do we need to run a function indirectly when I can do it on myself which is much more easier , what are the befifits to use a delegate

29th Aug 2017, 3:15 AM
prashanth m
prashanth m - avatar
5 odpowiedzi
+ 4
You never 'need' to use one thing, there's almost always different approaches. But they are perfect for things like button events. Or, if you need to call a bunch of methods always in synch (one after another), they are very elegant for doing that.
29th Aug 2017, 2:31 PM
Rrestoring faith
Rrestoring faith - avatar
+ 11
Not that I know C#, but this might be a beneficial read: https://stackoverflow.com/questions/2019402/when-why-to-use-delegates
29th Aug 2017, 4:18 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Delegates are easier. They make things more 'elegant' and compact when used properly. You don't 'need' them though. They are excellent if you ever want to pass methods as parameters. For example, button events: to define what methods would be called on click.
29th Aug 2017, 4:46 AM
Rrestoring faith
Rrestoring faith - avatar
0
thanks man but any real need to use delegates?
29th Aug 2017, 5:04 AM
prashanth m
prashanth m - avatar
0
thanks a Lot man
29th Aug 2017, 2:35 PM
prashanth m
prashanth m - avatar