In Brief

This chapter discussed how to work with and create your own collections in C#. Here's an overview of the topics we've discussed:

  • Arrays, which are supported by the System.Array class. This is actually an abstract class; you're better off using the standard array syntax in C#. Arrays support the methods and properties of the System.Array class.

  • Bit arrays, based on the BitArray class, let you access the individual elements of an array as bits.

  • ArrayList collections work much like arrays, except that they're extensible. You can add and remove elements in array lists using the Add and Remove methods.

  • Hashtable collections are dictionary collections that let you store values using keys. Instead of an array index, you pass the key to the hash table to access the corresponding value.

  • Queue collections are first-in first-out, FIFO, collections, much like the queues in front of a theater. You add elements to the end of a queue with the Queue method and remove them from the front with the Dequeue method.

  • Stack collections are first-in last-out, FILO, collections, much like the stacks of plates in cafeterias. You add an element to a stack with the Push method and remove an element with the Pop method.

  • You can create your own collections by implementing the appropriate interfaces. The ICollection interface is the official collection interface, with Count , IsSynchronized , and SyncRoot properties, as well as the CopyTo method.

  • Indexers enable you to use the [] operator with your custom collections.

  • The IEnumerator interface enables you to add an enumerator to your collection, which means that you can use foreach with your collection. You can also use an enumerator to iterate over your collection directly.

  • You can also implement the IComparable and IComparer interfaces to support sorting in your custom collections.



Microsoft Visual C#. NET 2003 Kick Start
Microsoft Visual C#.NET 2003 Kick Start
ISBN: 0672325470
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net