Different Ways of representing Lambdas

Today I had some free time at work since my batch process was taking an hour to run. During this time, I was investigating the beauties of lambda expression. I have found lambda expressions to be very flexible and versatile. What I mean is, your lambda expression can be as long and as small as you need it. If you find that in certain portion of your code, it would be much more easier to read if there is less noise from language, than you can use type inference. Places where you feel the code would be easier to read if there is more explicit types declared, should have proper parentheses and return statement than by all means using statement syntax  form of lambda expression. If you find the lambda expressions getting polluted by too much code and thus making it harder to read than by all means point the lambda expression to a method that does all the complicated logic. Here are different ways I have been able to express lambda statements.

image

In the above code, you would notice that i have expressions that have no data type and return statements where as some expressions have explicit data type and return statement. I also have a lambda expression that simply points to a method. Basically you can make lambda expressions as complex and as simply as you want it to be.

No Comments