.NET interview questions: - How will you distinguish between 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 different types of collection in .NET and C#: -
Also see our tutorials on interview questions and answers for Dotnet
View more author’s blog on Most asked Dotnet interview questions
write a comment