C # Set Queue

Source: Internet
Author: User

1. Queue Definition

The System. Collections. Queue class indicates the object's first-in-first-out set. objects stored in the Queue are inserted at one end and removed from the other end.

2. Advantages

1. sequential processing of sets (first-in-first-out ).

2. elements that can accept null values and repeat are allowed.

3. Queue Constructor

Constructors

Note

Queue ()

Initialize a new instance of the Queue class. This instance is empty and has the default initial capacity (32) and uses the default growth factor (2.0 ).

Queue (ICollection)

Initializes a new instance of the Queue class. This instance contains elements copied from the specified set, has the same initial capacity as the number of copied elements, and uses the default growth factor.

Queue (Int32)

Initialize a new instance of the Queue class. This instance is empty and has the specified initial capacity and uses the default growth factor.

Queue (Int32, Single)

Initialize a new instance of the Queue class. This instance is empty and has the specified initial capacity and uses the specified growth factor.

4. Attributes of Queue

Attribute name

Note

Count

Obtains the number of elements contained in a Queue.

5. Queue Method

Method Name

Note

Void Clear ()

Remove all objects from the Queue.

Bool Contains (object obj)

Determine whether an element is in the Queue.

Object Clone ()

Create a superficial copy of the Queue.

Void CopyTo (Array array, int index)

Copy the Queue element from the specified Array index to the existing one-dimensional Array.

Object Dequeue ()

Remove and return the object at the beginning of the Queue.

Void Enqueue (object obj)

Add the object to the end of the Queue.

Object Peek ()

Returns the object at the beginning of the Queue, but does not remove it.

Object [] ToArray ()

Copy the Queue element to the new array.

Void TrimToSize ()

Set the capacity to the actual number of elements in the Queue.

 

6. Queue usage example

 

Code
 Class Program
{
Static void Main (string [] args)
{
// Create a queue
Queue myQ = new Queue ();
MyQ. Enqueue ("The"); // enter The queue
MyQ. Enqueue ("quick ");
MyQ. Enqueue (

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.