Hi,
it is true that handcoded version will be a bit faster, but unless you know that performance is the key issue of your application, I wouldn't worry about that. The LINQ version of the code would look like this:
IEnumerable<List<double>> queryResults = /*...*/
var aggregates =
from ds in queryResults
select new {
First = ds[0], Last = ds[ds.Count - 1],
Lowest = ds.Min(), Highest = ds.Max() };
I think this is definitely easier to read :-). If the nested thing (ds
) isn't of type List
then you'll need to use First()
and Last()
extension methods instead of direct indexation.
Note that if you're interested in performance, you could also use Parallel LINQ, which runs the query on multiple threads. For short list, there is no real reason to do that, but if the collection is large, it may give you better performance (better than single-threaded hand-coded version).