Delegates & Events



21. What are the design patterns .Net provides to accomplish asynchronous operations?  

The .NET Framework provides two design patterns for asynchronous operations:
Asynchronous operations that use IAsyncResult objects.
Asynchronous operations that use events.
The IAsyncResult design pattern allows for a variety of programming models, but is more complex to learn and provides a flexibility that most applications do not require. Where possible, class library designers should implement asynchronous methods using the event-driven model.



22. Can events have access modifiers?  

Events are always public as they are meant to serve every one-register ing to it. But you can access modifiers in events. You can have events with protected keyword, which will be accessible only to inherited classes. You can have private events only for object in that class.


23. Do events have return type.  

No, events do not have return type.


24. What is the difference between delegate and events?  

•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 by adding the layer and making it a publisher and subscriber model.



25. How can we implement observer pattern in .NET?  

Observer patterns can be implemented using “Delegates” and “Events”. We leave this to the readers to implement one sample code for observer patterns.


.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions