Skip to content

Array.FindIndex has incorrect ArgumentOutOfRangeException description for 'startIndex' parameter. #9719

Open
@Fast-Nick

Description

@Fast-Nick

Example of what it looks like today (see bottom line of documentation):

        //     .........
        // Exceptions:
        //   T:System.ArgumentNullException:
        //     array is null. -or- match is null.
        //
        //   T:System.ArgumentOutOfRangeException:
        //     startIndex is outside the range of valid indexes for array.
        public static int FindIndex<T>(T[] array, int startIndex, Predicate<T> match);

It effectively says that the method accepts [0 <= startIndex < Length] with Length exclusive.
But what the method actually accepts is [0 <= startIndex <= Length] with Length inclusive.

The real behavior of the startIndex is identical to String.Substring, which has the following description instead:

        //   T:System.ArgumentOutOfRangeException:
        //     startIndex is less than zero or greater than the length of this instance.

To be correct and easy to understand the FindIndex documentation should thus say:

        //     startIndex is less than zero or greater than the length of the array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.RuntimeuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions