我有這樣的代碼:我如何使這個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