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: - events can be included in interfaces
- events can only be invoked by the containing class
- 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#
|