C# Queue Clear

Description

Queue Clear removes all objects from the Queue .

Syntax

Queue.Clear has the following syntax.


public void Clear()

Example


using System;/*ww w.  j  a  va 2 s  .  co m*/
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Queue<string> numbers = new Queue<string>();
        numbers.Enqueue("one");
        numbers.Enqueue("two");
        numbers.Enqueue("three");
        numbers.Enqueue("four");
        numbers.Enqueue("five");

        foreach( string number in numbers )
        {
            Console.WriteLine(number);
        }
        numbers.Clear();
        Console.WriteLine("\nqueueCopy.Count = {0}", numbers.Count);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack