Skip to content

Add regression tests for possible bug in OrderedEnumerable.Last{OrDefault} #19549

@jamesqo

Description

@jamesqo

I am not too familiar with OrderedEnumerable, but while making changes during dotnet/corefx#14174 I noticed there was a discrepancy between Last and LastOrDefault.

Code in Last: https://github.com/dotnet/corefx/blob/master/src/System.Linq/src/System/Linq/OrderedEnumerable.cs#L416. The result of comparer.Compare is compared with >= to 0.

Code in LastOrDefault: https://github.com/dotnet/corefx/blob/master/src/System.Linq/src/System/Linq/OrderedEnumerable.cs#L447 The result of comparer.Compare is compared with > to 0.

I assume this is trying to somehow find the maximum value of the enumerable? If that is the case, is the latter version correct?

cc @JonHanna @VSadov

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions