I am confused that what is the actual role of a delegate?
I have been asked this question many times in my interviews, but I don't think that interviewers were satisfied with my answer.
Can anyone tell me the best definition, in one sentence, with a practical example?
In Event communication sender does not know which object will handle the event. Delegate is type which hold the reference of method. Delegate has signature and holds reference to method which matches its signature so Delegate is like type safe function pointer.
button1.Click += new System.EventHandler(button1_Click) System.EventHandler is declared as a delegate here In .net Events work on the concept of Delegate (like Button Click)
Delegate is used when you do not know which code to invoke at run time So at that time Delegate is used to handle Events
http://msdn.microsoft.com/en-us/library/ms173171(v=vs.80).aspx