Grabbing on the knowledge!
Well, these two terms are the most interesting and responsive in terms of code structure…
Events: It can be described as something that happened followed by a response. For example, a button click, menu selection, and file transfer completion. An events pop-up is inevitable. The system stays in the dormant state until the time the event does not occur and then catalyze to handle it.
In GUI environment, the frequency of the event is uncontrollable thus it raises. For example, if you click a button, you might raise an event as Click event. A ListChanged event raises when a drop-down list is been added.
While other classes will be interested in responding but, they would not be bothered by the fact how did the response. The button says, “I was clicked”, and the functioning of the classes triggers appropriately.
Delegates: An encapsulating method is known as a delegate. When a delegate is been created, it specifies its method signature and return type. Other, methods can be encapsulated using this delegate.
Creating a delegate:
For creating a delegate you need to use a keyword as ‘delegate’, then the method signature and return type can be delegated as in the following code:
|public delegate str FindName (object o1, object o2)
This declaration defines a delegate FindName, which are going to encapsulate any method that takes two parameters and returns an
As the delegate is defined, it would be capable of encapsulating a member method by creating an instance of the delegate, reverting to a method that matches with the same return type and signature. Now, look into the described example that defines delegate which has no method body because the method body is not been defined here. It’s been simply mentioned that it can encapsulate any method having the same signature type. You, need not be worried about the fact, how it does process… Unless and until the correct parameter or return type is been considered.
Hope this has solved your query for the terms...
All The Best!