Considerations for selecting a collection class
Be careful when selecting the system. Collections class. The incorrect type may restrict your use of the set.
Consider the following:
Do you need a sequence list where elements are generally discarded after retrieving their values?
If necessary, consider using the queue class or queue <(of <(T>) generic class when you need first-in-first-out (FIFO) behavior. Consider using a stack class or a stack <(of <(T>)> generic class when you need a later, first-in-first-out (LIFO) behavior.
If not, consider using other collections.
Do I need to access elements in some order, such as FIFO, lifo, or random access?
The queue class and the queue <(of <(T>)> wildcard class provide FIFO access.
Stack class and stack <(of <(T>)> generic class provide LIFO access.
Shortlist <(of <(T>) generic classes allow sequential access from the beginning to the end or from the end to the beginning.
Other sets provide random access.
Do I need to access each element through indexes?
The arraylist, stringcollection, and list <(of <(T>)> generic classes provide access to elements through the zero-start index of an element.
Hashtable, sortedlist, listdictionary, stringdictionary, and dictionary <(of <(tkey, tvalue>) and sorteddictionary <(of <(tkey, tvalue>) generic classes provide access to elements through element keys.
Nameobjectcollectionbase and namevaluecollection classes and keyedcollection <(of <(tkey, titem>) and sortedlist <(of <(tkey, tvalue>) A generic class provides access to an element through its element index starting from scratch or through its element key.
Will each element contain a combination of values, keys, and values, or a combination of keys and values?
One Value: any set of generic Interfaces Based on the ilist interface or ilist <(of <(T>)>.
One key and one value: Use any set of idictionary-based or idictionary <(of <(tkey, tvalue>) Generic interfaces.
A value with an embedded key: uses the keyedcollection <(of <(tkey, titem>)> generic class.
One key and multiple values: Use the namevaluecollection class.
Do I need to sort elements in a different way than the input element method?
The hashtable class sorts elements by their hash code.
Sortedlist class and sorteddictionary <(of <(tkey, tvalue>) and sortedlist <(of <(tkey, tvalue>) generic classes are sorted by keys based on The Implementation of The icomparer interface and the icomparer <(of <(T>) interface.
Arraylist provides the sort method, which accepts the icomparer implementation as a parameter. Its corresponding generic class (list <(of <(T>) provides the sort method, which accepts icomparer <(of <(T>) the implementation of generic interfaces is used as parameters.
Do you need quick search and retrieval of information?
For a small set (10 or fewer items), listdictionary is faster than hashtable. Dictionary <(of <(tkey, tvalue>) generic classes provide faster searches than sorteddictionary <(of <(tkey, tvalue>) generic classes.
Do I need to accept only the string set?
Both stringcollection (based on ilist) and stringdictionary (based on idictionary) are located in the system. Collections. Specialized namespace.
In addition, by specifying the string class for the generic type parameter, you can use any generic set class in the system. Collections. Generic namespace as a strongly typed string set.