This code:
IEnumerable<IEnumerable<int>> numbas = new[] {new[] {0, 1}, new[] {2}, new[] {3, 4, 5}};
var flattened = numbas.SelectMany(a => a);
extracts a single flattened enumerable list of numbers from several sources. Resharper warns that it's possible that a
(the second one) is being enumerated multiple times -- but this is silly; each source is being enumerated once only. Yes, the symbol a
is going to be enumerated multiple times, but there will be a different source under it each time.
Did I miss something, or is this an erroneous warning coming out of Resharper?
Yes, this is an erroneous warning. You can see if you take a look at the implementation of SelectMany
- there's only one enumeration of the nested element:
foreach (TSource element in source) {
foreach (TResult subElement in selector(element)) {
yield return subElement;
}
}
Here's the YouTrack issue for this: http://youtrack.jetbrains.com/issue/RSRP-413613
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With