Something like that:
void SomeFunc()
{
int InsideVar = 1;
EventHandler handler = (s, e) => { MessageBox.Show(InsideVar.ToString()); };
SomeEvent += handler;
}
And then SomeEvent is called after the execution of SomeFunc. I really tested it, and it worked, but cannot understand why. I thought InsideVar would be on the stack and stop after the function was executed. I was expecting an exception. Can someone please clarify this?
source
share