[问题] 使用Lambda注册的Event最后怎么了?

楼主: yan04870449 (杨伯)   2014-03-05 16:32:54
class MyClass
{
static public event Action OnCall;
}
class Car
{
public void Start()
{
MyClass.OnCall += () =>
{
//做一些事情
};
}
}
上面只是用来说明这个问题而已
范例中,我使用Lambda再Car的instance里面注册了事件
但我并没有注销这个事件,当这Car的instance被移除了
之后这个被注册进去的匿名函式跑哪去了?
然后当OnCall事件又发生的时候,会发生什么事吗?
作者: tooto1985 ( )   2014-03-05 22:27:00
你执行看看不就知道结果了吗?
作者: Litfal (Litfal)   2014-03-06 18:41:00
GC。instance真被移除了又怎么会触发OnCall事件?

Links booklink

Contact Us: admin [ a t ] ucptt.com