struct SomeStruct
{
public int Num { get; set; }
}
class Program
{
static Action action;
static void Foo()
{
SomeStruct someStruct = new SomeStruct { Num = 5 };
action = () => Console.WriteLine(someStruct.Num);
}
static void Main()
{
Foo();
action.Invoke();
}
}
- Is a copy of someStruct created when the lambda is created?
- Is a copy of someStruct created when Foo returns?
- Can I verify that copying doesn't occur? In C++ I'd implement the copy constructor and print from inside it.
Citations from the standard will be appreciated. Any relevant online articles as well.