Reverts list. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Reverts list.

Demo Code

/********************************************************************
 *  FulcrumWeb RAD Framework - Fulcrum of your business             *
 *  Copyright (c) 2002-2010 FulcrumWeb, ALL RIGHTS RESERVED         *
 *                                                                  *
 *  THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      *
 *  FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        *
 *  COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       *
 *  AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  *
 *  AND PERMISSION FROM FULCRUMWEB. CONSULT THE END USER LICENSE    *
 *  AGREEMENT FOR INFORMATION ON ADDITIONAL RESTRICTIONS.           *
 ********************************************************************/
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Collections;
using System;// w  w w.  j  av a 2  s  .  c  o m

public class Main{
        //-------------------------------------------------------------------------
    /// <summary>
    /// Reverts list.
    /// </summary>
    /// <param name="list">list to revert</param>
    /// <returns>reverted list</returns>
    static public IList Reverse(IList list)
    {
      if (list != null)
      {
        ArrayList result = new ArrayList(list.Count);
        for (int i = list.Count - 1; i >= 0; i--)
        {
          result.Add(list[i]);
        }
        return result;
      }
      return null;
    }
        //-------------------------------------------------------------------------
    /// <summary>
    /// Reverts list.
    /// </summary>
    /// <param name="list">list to revert</param>
    /// <returns>reverted list</returns>
    static public IList<T> Reverse<T>(IList<T> list)
    {
      if (list != null)
      {
        List<T> result = new List<T>();
        for (int i = list.Count - 1; i >= 0; i--)
        {
          result.Add(list[i]);
        }
        return result;
      }
      return null;
    }
}

Related Tutorials