Enumerable.Single and Enumerable.SingleOrDefault overloaded implementations are inconsistent #14388
Labels
area-System.Linq
enhancement
Product code improvement that does NOT require public API changes/additions
Milestone
There is an inconsistency between the implementations of Enumerable.Single() and Enumerable.Single(predicate). Similarly there is another similar inconsistency between the implementations of Enumerable.SingleOrDefault() and Enumerable.SingleOrDefault(predicate)
The overloads which accept a predicate enumerate the whole sequence before eventually throwing, even if more than one matching elements were already found:
For consistency and performance reasons, it may be a good idea to make Enumerable.Single(predicate) and Enumerable.SingleOrDefault(predicate) methods able to fail fast and to throw an
InvalidOperationException
as soon as a second matching element is found.If that seems like a reasonable change, I would gladly submit a pull request.
The text was updated successfully, but these errors were encountered: