ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

EnqueueAll

Enqueues all objects from an IEnumerable<T> to the specified queue.

Source

/// <summary>
/// Extensions to the <see cref="Queue{T}"/> class.
/// </summary>
public static class QueueExtensions
{
    /// <summary>
    /// Enqueues all the specified objects.
    /// </summary>
    /// <typeparam name="T">The type of objects in the queue.</typeparam>
    /// <param name="queue">The queue.</param>
    /// <param name="items">The items to enqueue.</param>
    public static void EnqueueAll<T>(this Queue<T> queue, IEnumerable<T> items)
    {
        foreach (var item in items)
            queue.Enqueue(item);
    }
}

Example

Queue<string> queue = new Queue<string>();
queue.EnqueueAll(new string[]{"A", "B", "C"});

Author: Virtlink

Submitted on: 2 feb. 2012

Language: C#

Type: System.Collections.Generic.Queue<T>

Views: 5012