.NET Samples - How To: Collections

This section includes the following samples:

ICollection Sample

Clone Sample

List Sample

HashTable Sample

Collections Sample

ICollection Sample

This sample demonstrates how to create a class that is derived from the ICollection interface.

Namespaces used in this sample:

System; System.IO; System.Collections

Classes used in this sample:

Console; String; Array; Object; Exception; Operation; InvalidOperationException; Import; StringWriter; EventArgs; Page

Clone Sample

This sample demonstrates using cloning on an ArrayList. Cloning performs a 'shallow' copy of the ArrayList, meaning that any object references in the original list are copied by the target list rather than taking actual copies of the objects themselves. If the cloned list is modified, so is the original, when the list contains object references.

Namespaces used in this sample:

System; System.IO; System.Collections

Classes used in this sample:

Console; String; ArrayList; Array; Object; StringWriter; Import; Page; EventArgs; Type

List Sample

This sample illustrates how to create and use an ArrayList, including using a foreach (For Each in Visual Basic) command to loop through the list.

Namespaces used in this sample:

System; System.IO; System.Collections

Classes used in this sample:

Console; String; Type; ArrayList; Array; Object; Import; StringWriter; EventArgs; Page

HashTable Sample

This sample illustrates how to create and use a hash table. A hash table is a collection of key/value combinations organized for fast searching.

Namespaces used in this sample:

System; System.IO; System.Collections

Classes used in this sample:

Hash; Table; Console; Object; String; EventArgs; Hashtable; Import; ListBox; StringWriter; Page; Exception; Convert

Collections Sample

This sample illustrates three different collection types: Queue, SortedList, and Hashtable.

Namespaces used in this sample:

System; System.IO; System.Collections

Classes used in this sample:

String; Console; Queue; SortedList; Hash; Hashtable; Environment; StringWriter; Array; Import; Page; Math; EventArgs; Object