Where is this capture stored in this C# Lambda? -


all of posts c# lambdas says captures references variables.

but how can this?

private system.action lambda; void start()  {     int = 0;     lambda = () => {         i++;         debug.log(i);      }; } void update() {     lambda(); } 

this print out 1..2...3...etc

my understanding variable allocated on stack, referenced. after start() exits, should destroyed, causing undefined behavior when lambda() called.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -