What are events and delegates?

3 votes
197 views
Tarun Kumar asked 15-Nov-2017 in programming by Tarun Kumar

What are events and delegates?

1 Answer

1 votes
akriti kashyap answered 17-Nov-2017 by akriti kashyap
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.
What are events and delegates?
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 str.  

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.

What are events and delegates?

Hope this has solved your query for the terms...
All The Best!

UTKARSHASINGHROUL commented 16-Mar-2019 by UTKARSHASINGHROUL
Thank you for your answer.
       0