I've been trying figure out why lambda expressions don't feel intuitive to me yet. I suspect part of it may be because when I skim code, I sometimes internally translate it to my native language for my own clarity. For example:
endDate.Value = someNullableDate ?? (object)DBNull.Value;
// I could read as:
set endDate to someNullableDate or, if null, to (object)dbNull
An example from another language:
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.
So how would one read the lambda expression in:
var myList = new List<String>(/* various string values */);
var foo = myList.Select(s => s.Trim()).ToList(); //?
In lambda expressions, the lambda operator => separates the input parameters on the left side from the lambda body on the right side.
the operator => has nothing to do with linq - it's a lambda expression. It's used to create anonymous functions, so you don't need to create a full function for every small thing.
Lambda (uppercase/lowercase Λ λ) is a letter of the Greek alphabet. It is used to represent the "l" sound in Ancient and Modern Greek. In the system of Greek numerals, it has a value of 30.
Overview of Lambda Programming Languages Lambda allows developers to implement custom runtimes 2, but also offer a list of execution environments available out-of-the-box. Implementing applications in these 'default' environments are the ones this guide is going to cover.
I would read this as:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With