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 类的新实例,该实例为空,具有默认初始容量并使用默认增长因子。 |
| Queue(ICollection) |
初始化 Queue 类的新实例,该实例包含从指定集合复制的元素,具有与所复制的元素数相同的初始容量并使用默认增长因子。 |
| Queue(Int32) |
初始化 Queue 类的新实例,该实例为空,具有指定的初始容量并使用默认增长因子。 |
| Queue(Int32, Single) |
初始化 Queue 类的新实例,该实例为空,具有指定的初始容量并使用指定的增长因子。 |
属性
| Count |
获取 Queue 中包含的元素数。 |
| IsSynchronized |
获取一个值,该值指示是否同步对 Queue 的访问(线程安全)。 |
| SyncRoot |
获取可用于同步对 Queue 的访问的对象。 |
方法
| Clear() |
从 Queue 中移除所有对象。 |
| Clone() |
创建 Queue 的浅表副本。 |
| Contains(Object) |
确定某元素是否在 Queue 中。 |
| CopyTo(Array, Int32) | |
| 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 中元素的实际数目。 |
浙公网安备 33010602011771号