Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     

QuestPond’s Interview Questions & Answers on .NET

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.


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?


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 more step by step learning .NET.

Helpful Website Url
Share this article   |    Print    |    Article read by 2910 times
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 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: