我有这样的代码:我如何使这个lambda工作?
String temp = txtForm.Rtf;
foreach (ReplaceStrut rs in replaceArray) {
temp = temp.Replace(rs.getNeedle(), rs.getReplacement());
}
if (this.InvokeRequired) {
this.Invoke(temp => txtForm.Rtf = temp);
} else {
txtForm.Rtf = temp;
}
但它不会编译。它抱怨两件事:“不能将lambda表达式转换为类型'System.Delegate',因为它不是一个委托类型”,并且“一个名为'temp'的局部变量不能在这个范围内声明,因为它会带来不同的意义'temp',已经在'父级或当前'范围内用于表示其他内容'
这两个错误都在lambda行上。我该如何做这项工作,我做错了什么?
从来没有见过这样的语法:p不知道如果我喜欢它。 – leppie 2009-12-05 16:31:52
'new Action((=)...>)语法在生成的IL到'(Action)((=> ...>)'方面是相同的。 – 2009-12-05 16:58:49