- public static void ReverseArray<T>(this T[] inputArray)
- {
- T temp = default(T);
- if (inputArray == null)
- throw new ArgumentNullException("inputArray is empty");
- if (inputArray.Length > 0)
- {
- for (int counter = 0; counter < (inputArray.Length / 2); counter++)
- {
- temp = inputArray[counter];
- inputArray[counter] = inputArray[inputArray.Length - counter - 1];
- inputArray[inputArray.Length - counter - 1] = temp;
- }
- }
- else
- {
- Trace.WriteLine("Reversal not needed");
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/300820135485.html
来源: http://www.codesnippet.cn/detail/300820135485.html