我有一个带有返回函数的属性的类。
public class Demo
{
public Func<string,int,bool> Something { get; set; }
}
如果我喜欢这样
Demo demo = new Demo();
string target;
demo.Something = (a,b)=>
{
//in here `a` contains a value.
//and I want to do:
target = a;
return true;
};
//later in the code target is null
//target here is null instead of having the value of `a`
如何将 a 的值分配给 lambda 中的目标变量,以便稍后在代码中重用它?