Pimeko

Untitled

Apr 12th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. public void Insert(T elt)
  2.         {
  3.             if (nbElements >= array.GetLength(0))
  4.             {
  5.                 T[] newArray = new T[array.GetLength(0) * 2];
  6.                 for (int i = 0; i < array.GetLength(0); i++)
  7.                 {
  8.                     newArray[i] = array[i];
  9.                 }
  10.                 array = newArray;
  11.             }
  12.  
  13.             array[nbElements] = elt;
  14.             nbElements++;
  15.         }
  16.  
  17.         public T At(int i)
  18.         {
  19.             if (i > -1 && i < nbElements)
  20.                 return array[i];
  21.             else
  22.                 throw new Exception("Index error");
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment