Quick Walkthrough of Collections and Genrics

by


The .NET Framework supports a variety of collection classes that can be used in different circumstances. Here are some points that give a quick summary of Collections and Genrics in framework 2.0

Basics

  1. The ArrayList is a simple collection of unordered items.
  2. The Add and AddRange methods of the ArrayList are used to add items to an ArrayList.
  3. The Insert and InsertRange methods of the ArrayList are used to insert items into specific places in a collection.
  4. The Remove, RemoveAt, and RemoveRange methods of the ArrayList are used to delete items from a collection.
  5. The indexer of the ArrayList can be used to iterate over a collection.
  6. The IEnumerable and IEnumerator interfaces can be used to enumerate through a collection as well.
  7. The foreach construct in Visual Basic and C# use the IEnumerable interface to concisely iterate over a collection.

Sequential Lists

  1. The .NET Framework supports the Queue and Stack classes to provide collections that represent sequential lists of items.
  2. The Queue is a first-in, first-out (FIFO) collection.
  3. The Queue class supports the Enqueue and Dequeue methods for adding and removing items from the collection.
  4. The Stack is a last-in, first-out (LIFO) collection.
  5. The Stack class supports the Push and Pop methods for adding and removing items, respectively, from the collection.
  6. Both sequential collection classes support Peek for viewing the next item in the collection without removing it.

Dictionaries

  1. The IDictionary interface provides the basic calling convention for all Dictionary collections.
  2. The Hashtable class can be used to create lookup tables.
  3. You can use a DictionaryEntry object to get at the key and value of an object in a Dictionary collection.
  4. The SortedList can be used to create list of items that can be sorted by a key.
  5. The IEqualityComparer can be used to construct hash values and compare values for classes in an arbitrary way.

Specialized Collections

  1. The BitArray class and the BitVector32 structure can both be used to perform bit-wise operations on a series of Boolean values.
  2. The StringCollection and StringDictionary classes are type-safe classes for storing strings.
  3. You can create case-insensitive versions of Hashtable and SortedList objects using the CollectionUtil class.
  4. NameValueCollection is a useful class for storing more than one value per key in a name/value collection.

Generic Collections

  1. Generic collections can be used to create more type-safe and potentially faster versions of their nongeneric counterparts.
  2. The generic List, Dictionary, Queue, Stack, SortedList, and SortedDictionary classes are type-safe versions of the collections.
  3. The new LinkedList generic class is a collection for storing items that know about their own relationship in the list, and it allows for iteration without having access to the collection itself.
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.