Collection operation

xiaoxiao2021-03-06  53

A suitable collection operation is often required for querying whether a keyword is in a collection, array, and collection cannot be done directly.

The SYSTEM.COLLECTION Name Space is available in the System.collection name space in the .NET system class library. This namespace not only supports a simple collection concept of past, but also supports the Dictionary style set by Windows Scripting Host Library. Other types of sets are also available. The following is a common collection list:

Collection Description ArrayList Performs a one-dimensional array of boolean values ​​with an increase in elements, these values ​​are stored internally, providing a very compact format to manage a series of Boolean Values ​​Dictionary Performing a key-value data for a set can store and retrieve the HashTable in the Dictionary object to perform a key value data to the collection, this collection is organized according to the hash value of the key. Accelerate the storage speed, improve storage efficiency, and retrieve data according to the nuise. ObjectList performs a random object collection. Because all data types can be represented by Object, this collection can be virtually saved any data. Queue Executes a FIFD (advanced first out) queue sortedList Perform a series of classified key values ​​to perform a LIFO (rear first out) stack structure. StringCollection sets a collection of string values

Compared with a Collection data type, the various classes available are more advantageous. But now the options and classes are more than the past, such as HashTabel and ObjectList, they offer a feature that is equivalent to the Collection object we are familiar with. For example, a HashTabel class can be used for functions that do not need to care for the alternative Collection model:

Imports system.collection

Public Sub Dosomething ()

Dim ht as new hashtabel () DIM Entry As Dictionaryentry

HT.Add (1, "Item 1") HT.Add (2, "Item 2")

For Each Entry in Ht System.Diagnostics.debug.writeline (entry.value) Next

End Sub

Like all key values, the elements of the collections are represented by the DictionaryEntry object to access the keys and values ​​of an element. Although HashTabel is slightly different from the VB6 Collection object, the code is very similar, and is generally consistent with the code collection class written by other collection classes in the SYSTEM.COLECTION name space.

Among them, Dictionary is not in the 1.1 library, there is only one abstract base class DictionaryBase, so use HashTable

转载请注明原文地址:https://www.9cbs.com/read-116884.html

New Post(0)