我一直在努力弄清楚为什么 lambda 表达式对我来说还不直观。 我怀疑部分原因可能是因为当我略读代码时,为了自己的清晰度,我有时会在内部将其翻译成我的母语。 例如:
endDate.Value = someNullableDate ?? (object)DBNull.Value;
// I could read as:
set endDate to someNullableDate or, if null, to (object)dbNull
另一种语言的例子:
for(int count = 0; count >= 42; count++) {
cout << "Count is " << count << endl;
}
// May read as:
from an integer "count" as zero to 42 inclusive, display "Count is " and then the integer.
那么如何读取 lambda 表达式:
var myList = new List<String>(/* various string values */);
var foo = myList.Select(s => s.Trim()).ToList(); //?
最佳答案
我会这样理解:
Select each item individually from myList into a variable s, using s, apply a Trim() on it and once done with all items in myList, convert the whole thing to a list.
关于c# - 你如何阅读 lambda 表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6413138/