Is copying performed when capturing a value-type into a lambda?

后端 未结 4 1288
花落未央
花落未央 2020-12-11 04:10
struct SomeStruct
{
    public int Num { get; set; }
}

class Program
{
    static Action action;

    static void Foo()
    {
        SomeStruct someStruct = new So         


        
4条回答
  •  被撕碎了的回忆
    2020-12-11 04:42

    It won't be copied, it creates a closure. Basically it'll encapsulate the structure in one object instead of creating it on the stack.

    If you want to be sure you can always use reflector, but there is no need for that, the behavior is explained on Raymond Chen blog.

提交回复
热议问题