C# System.Collections.Queue

 1 using System;
 2  using System.Collections;
 3  public class SamplesQueue  {
 4  
 5     public static void Main()  {
 6  
 7        // Creates and initializes a new Queue.
 8        Queue myQ = new Queue();
 9        myQ.Enqueue("Hello");
10        myQ.Enqueue("World");
11        myQ.Enqueue("!");
12  
13        // Displays the properties and values of the Queue.
14        Console.WriteLine( "myQ" );
15        Console.WriteLine( "\tCount:    {0}", myQ.Count );
16        Console.Write( "\tValues:" );
17        PrintValues( myQ );
18     }
19  
20  
21     public static void PrintValues( IEnumerable myCollection )  {
22        foreach ( Object obj in myCollection )
23           Console.Write( "    {0}", obj );
24        Console.WriteLine();
25     }
26  }
27  /* 
28  This code produces the following output.
29  
30  myQ
31      Count:    3
32      Values:    Hello    World    !
33 */

 

构造函数 

Queue()

初始化 Queue 类的新实例,该实例为空,具备默认初始容量并使用默认增加因子。android

Queue(ICollection)

初始化 Queue 类的新实例,该实例包含从指定集合复制的元素,具备与所复制的元素数相同的初始容量并使用默认增加因子。ios

Queue(Int32)

初始化 Queue 类的新实例,该实例为空,具备指定的初始容量并使用默认增加因子。api

Queue(Int32, Single)

初始化 Queue 类的新实例,该实例为空,具备指定的初始容量并使用指定的增加因子。数组

属性 

Count

获取 Queue 中包含的元素数。安全

IsSynchronized

获取一个值,该值指示是否同步对 Queue 的访问(线程安全)。app

SyncRoot

获取可用于同步对 Queue 的访问的对象。函数

方法 

Clear()

从 Queue 中移除全部对象。spa

Clone()

建立 Queue 的浅表副本。线程

Contains(Object)

肯定某元素是否在 Queue 中。code

CopyTo(Array, Int32)

从指定数组索引开始将 Queue 元素复制到现有一维 Array 中。

Dequeue()

移除并返回位于 Queue 开始处的对象。

Enqueue(Object)

将对象添加到 Queue 的结尾处。

Equals(Object)

肯定指定的对象是否等于当前对象。

(Inherited from Object)
GetEnumerator()

返回循环访问 Queue 的枚举数。

GetHashCode()

做为默认哈希函数。

(Inherited from Object)
GetType()

获取当前实例的 Type

(Inherited from Object)
MemberwiseClone()

建立当前 Object 的浅表副本。

(Inherited from Object)
Peek()

返回位于 Queue 开始处的对象但不将其移除。

Synchronized(Queue)

返回一个新的 Queue,它将包装原始队列,而且是线程安全的。

ToArray()

将 Queue 元素复制到新数组。

ToString()

返回表示当前对象的字符串。

(Inherited from Object)
TrimToSize()

将容量设置为 Queue 中元素的实际数目。

相关文章
相关标签/搜索