开发者

keyword event in c# [duplicate]

开发者 https://www.devze.com 2023-02-20 01:42 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Why do we need the “event” keyword while defining events ?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Why do we need the “event” keyword while defining events ?

in the MSDN exemple : http://msdn.microsoft.com/开发者_如何学运维fr-fr/library/w369ty8x(v=VS.80).aspx

If i delete the event keyword from the publisher class, my project work. so wy we add the key word event.

thanks


Because of encapsulation. If keyword 'event' will be removed then you will be able to invoke 'event' and even change it's subscriptions from external classes which do not own the event. See Jon's answer here. With event keyword you're sharing an event, without it you're giving an access to delegate.

0

精彩评论

暂无评论...
验证码 换一张
取 消