Enumerable.Single inconsistency - by Jon Skeet

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 639955 Comments
Status Closed Workarounds
Type Bug Repros 5
Opened 1/28/2011 12:14:30 PM
Access Restriction Public


The overload of Enumerable.Single without a predicate will throw an exception as soon as it finds a second element.

The overload with a predicate keeps going, even if it knows that it won't return a result. This is inconsistent.
Sign in to post a comment.
Posted by Air Breather on 6/24/2015 at 4:23 AM
Looks like this one is now tracked on the dotnet/corefx GitHub repository here: https://github.com/dotnet/corefx/issues/1254
Posted by Cory Nelson on 1/17/2014 at 12:53 PM
This issue still exists in 4.5 and despite functioning "correct", results in completely unintuitive performance behavior. Please correct it in the next release. Thank you.
Posted by Microsoft on 4/6/2011 at 3:11 PM
Thanks for reporting this issue you've encountered with Visual Studio!

This would be great to clean up, so that iterating the entire sequence is not required when using the Single overload that takes a predicate - we could fail fast upon finding a second match, similar to what we do when no predicate is specified.

However, as the perf benefit to be had here would be limited to Single's error case, this issue currently falls just below our bug triage cut line. We're marking the issue Won't Fix to indicate that we're not currently tracking to fix this issue in the next release of Visual Studio. We'll reactivate this bug over the next year if we get further than expected through our bug triage list, or if we revisit the bug for the following release.

Alex Turner
Program Manager
Visual Basic and C# Compiler
Posted by Microsoft on 1/28/2011 at 1:13 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)