.NET interview questions: -Elaborate differentiation delegate and an event?
- By Shiv Prasad Koirala in ASP.NET
- Sep 4th, 2011
- 6625
- 0
.NET interview questions: -Elaborate differentiation delegate and an event?
This is one of the important and most asked.NET interview questions. Delegate is basically an abstract strong pointer to a function or method while events are higher level of encapsulation over delegates.
Events are used by delegates internally.
Main differing reasons are as follows:-
• Actually, events use delegates in bottom. But they add an extra layer on the delegates, thus forming the publisher and subscriber model.
• As delegates are function to pointers, they can move across any clients. So any of the clients can add or remove events, which can be confusing. But events give the extra protection / encapsulation by adding the layer and making it a publisher and subscriber model.
Think that one of your clients doing this
c.XyzCallback = null
This will reset all your delegates to nothing and you have to keep searching where the error is.
See the following video on Events and Delegates in C#: -
Also see our tutorials on interview questions and answers for .NET
Regards,
View more author's blog on Most asked .NET interview questions
Shiv Prasad Koirala
Visit us @ www.questpond.com or call us at 022-66752917... read more