Пример #1
0
 public static void Add(ref InternalListStruct <T> list, T newValue)
 {
     list.count++;
     T[] array = list.data as T[];
     if (list.count > 1)
     {
         if (array == null)
         {
             list.data = new T[16];
         }
         else if (array.Length < list.count)
         {
             T[] newArray = new T[array.Length * 2];
             Array.Copy(array, newArray, array.Length);
             list.data = newArray;
         }
         (list.data as T[])[list.count - 1] = newValue;
     }
     else
     {
         if (array != null)
         {
             array[0] = newValue;
         }
         else
         {
             list.data = newValue;
         }
     }
 }
Пример #2
0
 public static void Clear(ref InternalListStruct <T> list)
 {
     T[] asArray = list.data as T[];
     if (asArray == null)
     {
         list.data = null;
     }
     else
     {
         Array.Clear(asArray, 0, list.count);
     }
     list.count = 0;
 }
Пример #3
0
 public static void Set(ref InternalListStruct <T> list, int i, T newValue)
 {
     if (list.count - 1 < i || i < 0)
     {
         throw new IndexOutOfRangeException();
     }
     T[] array = list.data as T[];
     if (array == null)
     {
         list.data = newValue;
     }
     else
     {
         array[i] = newValue;
     }
 }
Пример #4
0
 public static void RemoveAt(ref InternalListStruct <T> list, int i)
 {
     if (list.count - 1 < i || i < 0)
     {
         throw new IndexOutOfRangeException();
     }
     list.count--;
     T[] array = list.data as T[];
     if (array != null)
     {
         Array.Copy(array, i + 1, array, i, list.count - i);
         array[list.count] = null;
     }
     else
     {
         list.data = null;
     }
 }