I am learning about events in C#. I found out that they are just multicast delegates.
My confusion is that why do we have "event" keyword while they are delegate, can’t we do
the same as we use delegates.
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.
Events are essentialy properties whose types are delegates. The intent of the
eventkeyword is to denote what are actually events that an object fires (i.e. callback functions), versus properties that simply hold a delegate. This distinction is important to GUI tools that need to show you what events an object can fire. Of course this could have been done with an annotation, but that wasn’t the design that was chosen for C#.In a recent interview, Anders Hejlsberg (the creator of C#) mentions that if he were designing it over again, he would probably not make events so special.