c# - 你如何阅读 lambda 表达式?

标签 c# .net lambda

我一直在努力弄清楚为什么 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/

相关文章:

C++ Lambda 函数转换错误

c# - 通过 lambda 找出一个列表是否包含另一个列表值

c# - 从将动态参数作为输入的 lambda 中获取属性名称

C# 跳过所有代理异常 - 超时

c# - 无法使用从 skydrive 获取的文件流来创建 BitmapImage

作为参数传递给 onclick() 的 C# 变量未定义

c# - 获取当前网络连接的属性

c# - 两个站点之间的共享文件夹?

c# - 我可以检测应用程序是否正在 child 区运行吗?

c# - ServiceStack 验证不显示消息