is there anyway this LINQ could end up doing too much work?
c#, linq
Solution
[...] so only does the string building for one row (the first one returned). Is that correct?
That is correct.
Obviously placing a ".ToList()" in between the .Select() and the .First will cause it to build a list of strings and then only take the first one
Correct again.
is there any other way the above Linq could end up doing too much work?
No. What you have is just fine as it is.
I'd put the `First` on a new line, just so there's no horizontal scrolling and so that the reader will notice that it's called, as it's rather important, but there's no need to change the code.
Problem
I have a list of customers, for which I just want to return the customer name (joining forename and surname). Can easily be done with the following Linq: ``` return customers.Select(a => string.Format("{0} {1}", a.Forename, a.Surname).First(); ``` If I understand things correctly "Select" will only run for the rows demanded by the statement to it's right. So for the above code, rather than select building a list of strings and only using the first one (throwing the others away), the select statement only runs for the first row (demanded by .First()) and then terminates, so only does the string building for one row (the first one returned). Is that correct? Obviously placing a ".ToList()" in between the .Select() and the .First will cause it to build a list of strings and then only take the first one, but is there any other way the above Linq could end up doing too much work? This is something that I feel I should already be sure of the answer, but best to confirm it.