Section 7.2. The System.Collections Namespace


7.2. The System.Collections Namespace

The System.Collections namespace contains classes that implement a variety of collection types, including stacks and queues. A queue is a first-in, first-out data structure. The following code illustrates its use in Visual Basic:

     Dim textContent As String     Dim wordQueue As New Collections.Queue(  )     wordQueue.Enqueue("First")     wordQueue.Enqueue("in")     wordQueue.Enqueue("first")     wordQueue.Enqueue("out")     Do While (wordQueue.Count > 0)        textContent &= " " & CStr(wordQueue.Dequeue)     Loop     MsgBox(textContent) 

The output is "First in first out."

The System.Collections.Stack class implements a first-in, last-out stack structure, using the standard methods Push and Pop. See the Stack Class entry in Chapter 12 for information on its use.

New in 2005. The 2005 release of Visual Basic includes a new generics feature. The collection classes within the System.Collections namespace are perfectly suited for use with generics. See Chapter 10 for details on using collections with generics.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

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