Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/System.Private.CoreLib/src/System/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,35 @@ public static void Reverse(Array array, int index, int length)
}
}

public static void Reverse<T>(T[] array)
{
if (array == null)
throw new ArgumentNullException("array");

Reverse(array, 0, array.Length);
}

public static void Reverse<T>(T[] array, int index, int length)
{
if (array == null)
throw new ArgumentNullException("array");
if (index < 0 || length < 0)
throw new ArgumentOutOfRangeException((index < 0 ? "index" : "length"), SR.ArgumentOutOfRange_NeedNonNegNum);
if (array.Length - index < length)
throw new ArgumentException(SR.Argument_InvalidOffLen);

int i = index;
int j = index + length - 1;
while (i < j)
{
T temp = array[i];
array[i] = array[j];
array[j] = temp;
i++;
j--;
}
}

// Sorts the elements of an array. The sort compares the elements to each
// other using the IComparable interface, which must be implemented
// by all elements of the array.
Expand Down