简体   繁体   中英

Lambda Example in C#

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.

You don't really need lambdas to do that all you would need to do is

var ObjectProperty = Combo.EditValue.Property;

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

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.

this does not appear to need a lambda.
Can't you just use

var ObjectProperty = Combo.EditValue.Property

As far as lambda references try 101 LINQ Examples for starters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM