Closures in C# - initating a thread in a function call with a value type

前端 未结 3 636
天涯浪人
天涯浪人 2021-01-28 17:43

I have this code, which works as I wanted but I don\'t understand exactly why. Thinking about a stack in C, C++, I\'d guess that the p variable will be on the stack on each call

3条回答
  •  Happy的楠姐
    2021-01-28 17:52

    It's not about closures, here is no any value capturing.

    What happening here is that your p parameter is copied by value into the thread's function. Everytime you pass to a function a new value of p is copied to a function.

提交回复
热议问题