Reverse IList with while loop - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Reverse IList with while loop

Demo Code


using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections;

public class Main{
    public static void Reverse<T> (IList<T> list)
      {//from   w w  w.ja va 2s. c  o  m
         int end = list.Count - 1;
         int index = 0;
         while (index < end) {
            T tmp = list [index];
            list [index] = list [end];
            list [end] = tmp;
            ++index;
            --end;
         }
      }
}

Related Tutorials