【正文】
將成為第二個(gè)元素刪除或訪問(wèn)。簡(jiǎn)單地研究在不改變隊(duì)列的頭元素,使用 Peek 方法。擁擠的電梯的 5 行為類似于堆棧的第一人進(jìn)入擁擠的電梯 ,但 是最后一個(gè)人離開(kāi),而最后一個(gè)登上電梯 的人,確實(shí) 第一 個(gè) 到達(dá)目的地。 各 集合類型的異同 因?yàn)槊總€(gè)集合有相同的基本功能,作為一個(gè)可變大小的存儲(chǔ)介質(zhì)對(duì)象的集合類型彼此有很多共同點(diǎn),這并不奇怪。字典對(duì)象、收集類型 ,可用于傳統(tǒng)的 ASP 開(kāi)發(fā)的唯一的集合類型的功能。 RemoveAt, allows the developer to remove an element at a specific position in the ArrayList. Both Remove and RemoveAt dissect only one element from the ArrayList at a time. We can remove a chunk of elements in one fell swoop by using the RemoveRange method. This method expects two parameters: an index to start at and a count of total elements to remove. Finally, to remove all the contents of an ArrayList, use the Clear method . Working with the Hashtable Class The type of collection most developers are used to working with is the hash table collection. Whereas the ArrayList indexes each element numerically, a hash table indexes each element by an alphanumeric key. The Collection data type in Visual Basic is a hash table。 in a queue, the element that is added first will be the element that is removed or accessed first, whereas the second element added will be the second element removed or accessed. The .NET Framework provides support for the queue data structure with the Queue class. To add an element to the tail, use the Enqueue method. To retrieve and remove an element from the head of a queue, use Dequeue. As with the other collection types we’ve examined thus far, the Queue class contains a Clear method to remove all elements. To simply examine the element at the head without altering the queue, use the Peek method. As with all the other collections, the elements of a Queue can be iterated through using an enumerator or a For Each Next loop. Working with the Stack Class A stack is a data structure similar to a queue in that is supports only sequential , a stack does bear one major difference from a queue: rather than storing elements with a First In, First Out (FIFO) semantic, a stack uses Last In, First Out (LIFO). A crowded elevator behaves similar to a stack: the first person who enters the crowded elevator is the last person to leave, whereas the last person to board the elevator is the first out when it reaches its destination. Adding, Removing, and Accessing Elements in a Stack The .NET Framework provides an implementation of the stack data type with the Stack class. A stack has two basic operations: adding an element to the top of the stack, which is acplished with the Push method, and removing an element from the top of the stack, acplished via the Pop method. Similar to the Queue class, the Stack class also contains a Peek method to permit developers to access the top of the stack without removing the element. Similarities Among the Collection Types Because each collection has the same basic functionality—to serve as a variablesized storage medium for Objects—it is not surprising that the collection types have much in mon with one another. All have methods to add and remove elements from the collection. The Count property, which returns the total number of elements in the collection, is mon among all collection types. Conclusion The .NET Framework provides developers with a number of powerful collectiontype classes, greatly extending the functionality of the object, the sole collection type available for classic ASP developers. These collections, although each have unique capabilities, are more alike than they are different. All of them share similar methods and properties, and can all have their elements iterated through using a number of techniques.