<Member Name="Resize<T>(T[]@,System.Int32)" />
<Member Name="Reverse(System.Array)" />
<Member Name="Reverse(System.Array,System.Int32,System.Int32)" />
+ <Member Name="Reverse<T>(T[])" />
+ <Member Name="Reverse<T>(T[],System.Int32,System.Int32)" />
<Member Name="SetValue(System.Object,System.Int32)" />
<Member Name="SetValue(System.Object,System.Int32,System.Int32)" />
<Member Name="SetValue(System.Object,System.Int32,System.Int32,System.Int32)" />
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
private static extern bool TrySZReverse(Array array, int index, int count);
-
+
+ [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
+ public static void Reverse<T>(T[] array)
+ {
+ if (array == null)
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
+ Contract.EndContractBlock();
+ Reverse(array, 0, array.Length);
+ }
+
+ [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
+ public static void Reverse<T>(T[] array, int index, int length)
+ {
+ if (array == null)
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
+ if (index < 0)
+ ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
+ if (length < 0)
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
+ if (array.Length - index < length)
+ ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
+ Contract.EndContractBlock();
+
+ 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.
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
Contract.EndContractBlock();
- // The non-generic Array.Reverse is not used because it does not perform
- // well for non-primitive value types.
- // If/when a generic Array.Reverse<T> becomes available, the below code
- // can be deleted and replaced with a call to Array.Reverse<T>.
- int i = index;
- int j = index + count - 1;
- T[] array = _items;
- while (i < j)
- {
- T temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- i++;
- j--;
- }
-
+ Array.Reverse(_items, index, count);
_version++;
}