Why does trying to understand delegates feel like trying to understand the nature of the universe?

Kin picture Kin · Apr 20, 2010 · Viewed 7.4k times · Source

I've read two books, tons of examples. They still make next to no sense to me. I could probably write some code that uses delegates, but I have no idea why. Am I the only one with this problem, or am I just an idiot? If anyone can actually explain to me when, where, and why I would actually use a delegate, I'll love you forever.

Answer

Byron Whitlock picture Byron Whitlock · Apr 20, 2010

Delegates are just a way to pass around a function in a variable.

You pass a delegated function to do a callback. Such as when doing asynchronous IO, you pass a delegated function (a function you have written with the delegate parameter) that will be called when the data has been read off the disk.