I have some confusion regarding Events. What are the basic differences between C# Events and Methods?
I have some confusion regarding Events . What are the basic differences between C#
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
C#
Eventsare a specific form ofdelegates. If you have programmed in other languages, like C++, you could compare adelegateto a function (“method”) pointer – it points to some code in memory. When you call the pointer as a method, you actually call the method at the address the pointer points to.This is necessary to provide decoupling between the caller and the callee – so you don’t have to have all methods ready when you publish code that calls them (which, wouldn’t be possible – the Forms controls developers can’t possibly know the code that needs to be called when a
Buttonis pressed). You call the pointer, and the other developer sets it to an appropriate memory address later.P.S.
delegatesandEventshowever, have other advantages over plain function pointers – you can be sure that it will point to a good-looking method, taking the correct number and type of arguments and returning the correct type.