Manage Data by Using Specialized Collections
This objective means that you can use the classes that can be found in the System.Collections.Specialized namespace. Unfortunately, there are a bunch of classes that you’ll never use in a live environment (remember the magic keyword: Generics), but you’ll have to know them for the exam.
We’ll deal with the following classes in this post:
A StringCollection represents a strongly-typed collection of strings. You can add, remove, insert strings, and you can reference the items with and indexer. Use a generic List<string> instead for the exact same effect. A StringCollection can contain the null value.
A StringDictionary represents a dictionary, in which both the keys and the values are strings. Can contain null as value, but the keys cannot be nulls. You can reference on the items with the key string.
A simple structure that stores Boolean values or small integers in 32 bits of memory. The main difference between a BitArray and the BitVector32 is the size of it. A BitArray can grow unlimited, but the BitVector32 can be only 32 bits. It can contain only small integers or Boolean values (but not both of them at the same time).
You can create Sections into a BitVector32, each section represents an integer value. You can assign these sections to your BitVector32s, then retrieve their values using them as an index.
CollectionsUtil is a class which helps you generate case-insensitive string collections. It has two static methods, called CreateCaseInsensitiveHashtable and CreateCaseInsensitiveSortedList. The Hashtable method has two overloads, you can define the initial capacity of the table, or pass an object that implements IDictionary.
Then you can use these objects as everyday collections. The main difference is that they don’t make differences between the casings of a text. For example, when you add the string “Hello”, then “helLO” to the prepared Hashtable, you’ll get an exception, as the table already contains the string.
Provides an abstract base dictionary class for your custom collections. The key is a string, the values can be any kind of objects.
ListDictionary is a simple implementation of the IDictionary interface. This class is created when you’d deal with ten or fewer items in your dictionary, so you shouldn’t use it to store more key-value pairs. For bigger collections, use the Hashtable. If you are in doubt whether your collection will grow, use the HybridDictionary class.
HybridDictionary is a class that implements IDictionary (thus holds key-value pairs). As long as the collection is small, it uses a ListDictionary to store the items. If the collection grows out of the limitations of ListDictionary (10 entries), it switches to work with a Hashtable. Therefore it’s an ideal choice when you don’t know the size of your dictionary at compile time.