Home Dashboard Directory Help
Search

Enumerable.Single inconsistency by Jon Skeet


Status: 

Closed
 as Won't Fix Help for as Won't Fix


8
0
Sign in
to vote
Type: Bug
ID: 639955
Opened: 1/28/2011 12:14:30 PM
Access Restriction: Public
1
Workaround(s)
view
5
User(s) can reproduce this bug

Description

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.
Details
Sign in to post a comment.
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)
Sign in to post a workaround.
Posted by Air Breather on 1/24/2014 at 1:41 PM
Instead of

someEnumerable.Single(predicate)

use

someEnumerable.Where(predicate).Single()