Hi,
I'm trying to construct a LINQ query to search a complex (well, not simple anyway) collection (Items) for entries (themselves containing a smaller collection) whose sequence of values are equal and in the same order. Then a "probability" property of the first matching subitem should be updated and the element that matches should be removed.
Here is my first attempt. It is not complete but is indicative of where my thinking has been:
Items[i].Probability += Items.SubItems.Where(item => item.SequenceEqual(Items[i])).Select(result => result.Probability);
Some comments of my own on this:
- I get an error
"Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<double>' to 'double'".</double>
So the select statement isn't return a double and i haven't yet hit on the operator that will do that. Is it wrong to look to use LINQ in this manner?
- The Where operator could return multiple elements. I'm not sure how to handle that.
- I have not yet managed to integrate the removal of matched elements once the compared element (Items[i]) has been updated.
I'll be very grateful to anyone that can offer useful input/guidance on how I should handle this query as I'm quite new to LINQ.
Regards,
Dave