public void RemoveAt () { var l = new UnorderedList<int>(new int[] { 1, 2, 3, 4, 5 }); l.RemoveAt(1); Assert.AreEqual( new int[] { 1, 5, 3, 4 }, l.ToArray() ); l.RemoveAt(2); Assert.AreEqual( new int[] { 1, 5, 4 }, l.ToArray() ); }
/// <param name="onException">To avoid generating garbage use a static method or a cached delegate</param> public void Execute() { defaultTimer.UpdateCurrentTime(); timesUpdated++; for (int i = 0; i < recurrentCallbacks.Length; i++) { var queue = recurrentCallbacks[i]; // Execute Delayed Deletes var delayedQueue = delayedRemoves[i]; if (delayedQueue.Count > 0) { lock (delayedQueue) { while (delayedQueue.Count > 0) { var reference = delayedQueue.ExtractLast(); for (int j = 0; j < queue.Count; j++) { if (queue.elements[j].id == reference.id) { queue.RemoveAt(j); break; } } } } } for (int j = 0; j < queue.Count; j++) { try { queue.elements[j].action(); } catch (Exception e) { Console.WriteLine(e); if (null != onException) { onException.Invoke(e); } } } } for (int i = 0; i < actionsStillWaiting.Count;) { if (actionsStillWaiting[i].ItsTime()) { try { actionsStillWaiting[i].action.Invoke(); } catch (Exception e) { Console.WriteLine(e); if (null != onException) { onException.Invoke(e); } } finally { actionsStillWaiting.RemoveAt(i); } } else { i++; } } TimedAction timedAction; while (queuedUpdateCallbacks.Dequeue(out timedAction)) { if (timedAction.ItsTime()) { try { timedAction.action(); } catch (Exception e) { Console.WriteLine(e); if (null != onException) { onException.Invoke(e); } } } else { actionsStillWaiting.Add(timedAction); } } }