Skip to content

ROS<T>.LastIndexOf(ROS<T> value) returns wrong index when 'value' is empty #13382

@GrabYourPitchforks

Description

@GrabYourPitchforks
Console.WriteLine("Hello".LastIndexOf(""));
Console.WriteLine("Hello".LastIndexOf("", StringComparison.Ordinal));
Console.WriteLine("Hello".AsSpan().LastIndexOf(""));
Console.WriteLine("Hello".AsSpan().LastIndexOf("", StringComparison.Ordinal));

// PRINTS:
// 4
// 4
// 0
// 4

The behavior of ROS<T>.LastIndexOf differs based on whether the char-specific overload is called or whether the generic T overload is called, as shown above. We should make the behavior consistent.

(To be fair, all of these APIs should be returning "5", not "4". I'll file a separate bug for that.)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions