Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




QuestPond: Interview Questions/Answers on .NET in Delegates & Events

What are Events?

Events are higher level of encapsulation over delegates. Events use delegates internally. Delegates are naked and when passed to any other code, the client code can invoke the delegate. Event provides a publisher / subscriber mechanism model.

So subscribers subscribe to the event and publisher then push messages to all the subscribers. Below is a simple code snippet for the same: -

Create a delegate and declare the event for the same.

public delegate void CallEveryone();

public event CallEveryone MyEvent;


Raise the event.

MyEvent();


Attached client methods to the event are fired / notified.

obj.MyEvent += Function1;


Do events have return type?

No, events do not have return type.

Can events have access modifiers?

Yes.

Can we have shared events?

Yes, you can have shared events, do note only shared methods can raise shared events.

See following video on Delegate and Events: -

Click and see here for learning .NET tutorials.


Helpful Website Url
http://www.questpond.com/
Share this article   |    Print    |    Article read by 3981 times
Author:
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site http://www.questpond.com for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles:
Related Interview Questions: