Hi all,
Depending on what I know, when I define a method in C#, the local variables in this method will be released from memory after finishing executing the block of this method [when GC wants],
but if I have an inline callback in a method, will these local variables be released from memory also ?
In the following example, the [x] variable will keep its value after finishing executing the method and the message will show the value of [x] without problem although it's in a callback !!
private void MyMethod()
{
int x = 1;
System.Timers.Timer t = new System.Timers.Timer(1000);
t.Elapsed += (sender, e) => MessageBox.Show((x++).ToString()); ;
t.Start();
}