1.58. C# queue

发布时间 : 2025-10-25 13:34:41 UTC      

Page Views: 9 views

A queue represents a collection of first-in, first-out objects. Queues are used when you need first-in, first-out access to items. When you add an item to the list, it is called queuing, and when you remove an item from the list, it is called queuing.

1.58.1. Methods and properties of the Queue class #

The following table lists some common properties of Queue class:

Attribute

Description

Count

Gets the number of elements contained in the Queue.

The following table lists some common methods of Queue :

Serial number

Method name & description

1

Public virtual void Clear (); removes all elements from the Queue.

2

Public virtual bool Contains (object obj); determines whether an element is in Queue.

3

Public virtual object Dequeue (); removes and returns the object at the beginning of Queue.

4

Public virtual void Enqueue (object obj); add an object to the end of the Queue.

5

Public virtual object [] ToArray (); copy Queue into a new array.

6

Public virtual void TrimToSize (); sets the capacity to the actual number ofelements in the Queue.

1.58.2. Example #

The following example demonstrates the use of Queue:

Example #

using System; using System.Collections; namespace CollectionsApplication { class Program { static void Main(string[] args) { Queue q = new Queue(); q.Enqueue('A'); q.Enqueue('M'); q.Enqueue('G'); q.Enqueue('W'); Console.WriteLine("Current queue: "); foreach (char c in q) Console.Write(c + " "); Console.WriteLine(); q.Enqueue('V'); q.Enqueue('H'); Console.WriteLine("Current queue: "); foreach (char c in q) Console.Write(c + " "); Console.WriteLine(); Console.WriteLine("Removing some values "); char ch = (char)q.Dequeue(); Console.WriteLine("The removed value: {0}", ch); ch = (char)q.Dequeue(); Console.WriteLine("The removed value: {0}", ch); Console.ReadKey(); } } } 

When the above code is compiled and executed, it produces the following results:

Current queue: A M G W Current queue: A M G W V H Removing values The removed value: A The removed value: M 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。