C# 中的 Lambda 示例
我仍在学习 C# 3.0 的一些功能,想知道以下是否可以简化为 lambda 表达式。
var SomeObject = Combo.EditValue;
var ObjectProperty = SomeObject.Property;
要在一行中从combo.editvalue 获取ObjectProperty?
另外,如果您能为我提供有关 Lambda 表达式的任何好的参考资料,我将不胜感激。
编辑:好的,发布的答案很棒,看来该示例不需要 Lambda 来满足解决方案。 不过,我会看一下参考链接。
I am still learning some of the features of C# 3.0 and want to know if the following can be reduced to a lambda expression.
var SomeObject = Combo.EditValue;
var ObjectProperty = SomeObject.Property;
To obtain ObjectProperty from the combo.editvalue in a single line?
Also, if you can provide me with any good references to Lambda expressions, it would be appreciated.
EDIT: Ok, the answers posted are great, it appears that the example does not need a Lambda to satisfy the solution. I will take a look at the reference links though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你并不真的需要 lambda 来做到这一点,你需要做的就是
我不确定 lambda 是否会让你更具可读性。
您可能需要阅读以下一些书籍来更详细地了解 Lambda 以及使用它们的原因:
更有效的 C#
C# 深入了解
MSDN 参考
You don't really need lambdas to do that all you would need to do is
I'm not sure a lambda is going to make that any more readable for you.
Here are some books you might want to take a look at to learn Lambdas in more detail, and also why you'd use them:
More Effective C#
C# In Depth
MSDN Reference
将它们合并到一行中,通过检查 EditValue 上的 Property 属性,您将面临 NullReferenceException 的风险。 :) 但是,这是一个关于 C# 3.0 的非常好的教程函数式编程。
Combining those into one line, you run the risk of a NullReferenceException, by checking the Property property on EditValue. :) But, here is a really great tutorial on C# 3.0 and functional programming.
这似乎不需要 lambda。
难道你不能只使用
lambda 引用尝试 101 LINQ Examples 对于初学者来说。
this does not appear to need a lambda.
Can't you just use
As far as lambda references try 101 LINQ Examples for starters.