Senator Guerra Souty original series calendar,replica hublot blue steel peach pointer collocation of rolex replica Rome digital scale, track type minute replica watches scale shows that the classical model is swiss replica watches incomparable, wearing elegant dress highlights.
mr-ponna.com

 

YOU ARE HERE: HOME Questions What s difference between delegate and events



Delegate vs Events

View(s): 44380

What’s difference between delegate and events?

Answer 1)
Class1 c = new Class1();
c.MyDeleageteCallback = new Class1.DomSomethingDelegate(this.Calculate);
 
This piece of code will work just fine with class1, but if we were to try to use it on class2, where there is the event keyword declared, we would get a compilation error.

In conclusion: an event declaration adds a layer of protection on the delegate instance. This protection prevents clients of the delegate from resetting the delegate and its invocation list, and only allows adding or removing targets from the invocation list.

Three main differences: 
  1. events can be included in interfaces 
  2. events can only be invoked by the containing class 
  3. events' signatures are constrained (depends on language and CLS compliance)
Events also add a pair of customizable methods similar to properties ("get" and "set").  
  • AddHandler and RemoveHandler in VB.NET
  • += and -= in C#
  Asked in:  LiquidHub   Expertise Level:  Experienced
  Last updated on Thursday, 29 July 2010
4/5 stars (23 vote(s))

Register Login Ask Us Write to Us Help