I am a list of lists with the same type of objects and I am trying to convert it to a single list with all the objects using linq.
How can I do this?
This is my current code:
var allTrackAreas =
_routables.Select(
routable =>
_centrifugeHelper.GetTrackAreasFromRoutable(routable, _trackAreaCutterParameters,
_allowedDestination.MatchedAreas[routable]))
.Where(area => area != null).ToList();
foreach (var testAction in _trackAreaCutterParameters.ConcurrentBagTestActions)
{
if (allTrackAreas.Any(areas => areas.Any(area => area.Id == testAction.TrackAreaId)))
{
currentActions.Add(testAction);
}
}
The variable allTrackAreas is a list of lists and I am using twice Any on it which is quite bad for efficiency. It would be much better if it was a simple list.
Where(area => area != null). Do you have null elements as well? I'll update my answer if so.Anytwice is "quite bad for efficiency"?