认为
public class Program
{
public static void Main(string[] args)
{
Program p = new Program();
A a = new A();
p.Do(a);
System.Threading.Thread.Sleep(1000);
a.Fire();
}
public void Do(A a)
{
int i = 5;
a.ChangeViewEvent += () =>
{
Console.WriteLine(i);
};
}
}
public class A
{
public delegate void ChangeView();
public event ChangeView ChangeViewEvent;
public void Fire()
{
if(ChangeViewEvent != null)
ChangeViewEvent();
}
}
什么时候ChangeViewEvent
被触发,事件处理程序仍然能够访问变量i
?我的意思是它不应该超出范围吗?