Workaround for not having lambdas that can capture managed variables

前端 未结 3 367
伪装坚强ぢ
伪装坚强ぢ 2020-12-31 10:29

In C++/CLI, you cannot create managed lambdas (like you can in C#), and thus you can\'t capture managed variables. You can create regular methods (rather than lambdas), but

3条回答
  •  长发绾君心
    2020-12-31 11:10

    If you look at a decompilation of a C# lambda, you'll see that the C# compiler does the same thing as your option #2. It's annoying to create a bunch of single-use classes, but that's what I'd recommend.

    With a C# lambda, when it creates the nested class instance, it uses that everywhere instead of the local variable. Keep that in mind as you write the method that uses the nested class.

提交回复
热议问题