c**a 发帖数: 316 | 1 event 貌似就是个delegate 啊,
比如下面代码有区别吗?
我试不出区别:(
class A{
public delegate m_EventHandler(object o, EventArgs, e);
public event m_EventHandler m_event;
public m_EventHandler m_event2;
}
貌似 m_event 和 m_event2 没有区别。 |
c**a 发帖数: 316 | 2
【在 c**a 的大作中提到】 : event 貌似就是个delegate 啊, : 比如下面代码有区别吗? : 我试不出区别:( : class A{ : public delegate m_EventHandler(object o, EventArgs, e); : public event m_EventHandler m_event; : public m_EventHandler m_event2; : } : 貌似 m_event 和 m_event2 没有区别。
|
c**a 发帖数: 316 | 3 MSDN 上看了下,
貌似是个历史遗留问题造成的。
虽然有些区别,但是其实event的存在是不必要的。
【在 c**a 的大作中提到】
|
k*k 发帖数: 508 | 4 估计看着清楚些,hoho
【在 c**a 的大作中提到】 : MSDN 上看了下, : 貌似是个历史遗留问题造成的。 : 虽然有些区别,但是其实event的存在是不必要的。
|
c**d 发帖数: 579 | 5 event is a special kind of delegate. It opens two and only two services to
outside world - add event handler and remove event handler. If you use a
delegate instead of event, any subscriber can set or change the value of
delegate. For example, they can set its value as null. Subscriber can also
know who is subscribing to the event, which leads to security problem. |
s*******d 发帖数: 59 | |
c**a 发帖数: 316 | 7 精辟。
MSDN 上随也这样写了, 但是偶就是没理解到。
被这么一说就明白了。
【在 c**d 的大作中提到】 : event is a special kind of delegate. It opens two and only two services to : outside world - add event handler and remove event handler. If you use a : delegate instead of event, any subscriber can set or change the value of : delegate. For example, they can set its value as null. Subscriber can also : know who is subscribing to the event, which leads to security problem.
|