Reverse Array Contents - CSharp System

CSharp examples for System:Array Operation

Description

Reverse Array Contents

Demo Code

// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.
using System.Diagnostics;
using System;/*from w w w . j a  v  a2 s.c  o m*/

public class Main{
        internal static void ReverseContents<T>(this T[] array, int start, int count)
        {
            int end = start + count - 1;
            for (int i = start, j = end; i < j; i++, j--)
            {
                T tmp = array[i];
                array[i] = array[j];
                array[j] = tmp;
            }
        }
        internal static void ReverseContents<T>(this T[] array)
        {
            ReverseContents(array, 0, array.Length);
        }
}

Related Tutorials