What are the names given to these 2 LINQ expressions
-
09-06-2019 - |
Question
I'm trying to find the correct names for these 2 "types" of coding expressions in LINQ so that I can refer to them correctly. I want to say that the first is called "Fluent Style"?
var selectVar = arrayVar.Select( (a,i) => new { Line = a });
var selectVar =
from s in arrayVar
select new { Line = s };
Solution
- First - calling an extension method. This style of coding is called "fluent interface" as you mentioned.
- Second method is called language integrated query
OTHER TIPS
the first isn't even really linq, its a lambda expression, with a type invariant object created. (a) => new { blah = b}
The second is a linq query filling an on the fly class that has a property Line. There is no hashrocket operator in this one, so this one is just plain old linq.
The name of the second form is "query comprehesion syntax", which the compiler translates into the first form.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow