private void IntQueueTestCopyTo(IQueue <int> q) { int[] arr = { 1, 2, 3, 4, 5 }; int[] arr_to_copy = new int[5]; arr_to_copy[0] = 1; arr_to_copy[4] = 5; q.Clear(); q.Enqueue(2); q.Enqueue(3); q.Enqueue(4); q.CopyTo(arr_to_copy, 1); Assert.AreEqual(arr, arr_to_copy); q.Enqueue(6); var ex = Assert.Throws <ArgumentException>(() => q.CopyTo(arr_to_copy, 1)); Assert.That(ex.Message, Is.EqualTo("The number of elements in the source Queue<T> is greater than the available space from arrayIndex to the end of the destination array.")); }
public virtual void TestCopyto() { Assert.IsTrue(q.Offer("item1")); Assert.IsTrue(q.Offer("item2")); Assert.IsTrue(q.Offer("item3")); Assert.IsTrue(q.Offer("item4")); Assert.IsTrue(q.Offer("item5")); var objects = new string[q.Count]; q.CopyTo(objects, 0); Assert.AreEqual(objects.Length, q.Count); }
/// <summary> /// Invoked by the <see cref="Signal"/> method to resume all /// waiting <see cref="Task"/>s. /// </summary> private void ResumeAll() { System.Diagnostics.Debug.Assert(BlockCount > 1); int nWaiting = BlockCount; Task[] blockedTasks = new Task[nWaiting]; _waitQ.CopyTo(blockedTasks, 0); _waitQ.Clear(); for (int i = 0; i < nWaiting; i++) { Task task = blockedTasks[i]; if (!task.Canceled) { task.Activate(this); } } }
/// <summary> /// Extract the <see cref="Task"/> instances contained in the specified /// wait queue. /// </summary> /// <param name="waitQueue">The wait queue.</param> /// <returns> /// An array of <see cref="Task"/>s contained in /// <paramref name="waitQueue"/>. /// </returns> protected static T[] GetBlockedTasks(IQueue <T> waitQueue) { T[] tasks; if (waitQueue != null) { tasks = new T[waitQueue.Count]; if (tasks.Length > 0) { waitQueue.CopyTo(tasks, 0); } } else { tasks = new T[0]; } return(tasks); }
/// <summary> /// Copies the elements of the <see cref="RepeatableQueue{T}" /> to an <see cref="Array" />, starting at /// a particular <see cref="Array" /> index. /// </summary> /// <param name="array"> /// The one-dimensional <see cref="Array" /> that is the destination of the elements copied /// from <see cref="RepeatableQueue{T}" />. The <see cref="Array" /> must have zero-based indexing. /// </param> /// <param name="index">The zero-based index in <paramref name="array" /> at which copying begins. </param> /// <exception cref="ArgumentNullException"> /// <paramref name="array" /> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="index" /> is less than zero. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="array" /> is multidimensional.-or- The number of elements in the source /// <see cref="RepeatableQueue{T}" /> is greater than the available space from <paramref name="index" /> to the end of /// the destination <paramref name="array" />.-or-The type of the source <see cref="RepeatableQueue{T}" /> cannot be /// cast automatically to the type of the destination <paramref name="array" />. /// </exception> public void CopyTo( Array array, int index) => internalQueue.CopyTo( array, index);
/// <inheritdoc /> public void CopyTo(Array array, int index) { _queue.CopyTo(array, index); }