Imports System
Imports System.Collections.Generic
Module Example
Sub Main
Dim numbers As New Stack(Of String)
numbers.Push("one")
numbers.Push("two")
numbers.Push("three")
numbers.Push("four")
numbers.Push("five")
For Each number As String In numbers
Console.WriteLine(number)
Next
Console.WriteLine(vbLf & "Popping '{0}'", numbers.Pop())
Console.WriteLine("Peek at next item to pop: {0}",numbers.Peek())
Console.WriteLine("Popping '{0}'", numbers.Pop())
Dim stack2 As New Stack(Of String)(numbers.ToArray())
For Each number As String In stack2
Console.WriteLine(number)
Next
Dim array2((numbers.Count * 2) - 1) As String
numbers.CopyTo(array2, numbers.Count)
Dim stack3 As New Stack(Of String)(array2)
For Each number As String In stack3
Console.WriteLine(number)
Next
Console.WriteLine(stack2.Contains("four"))
stack2.Clear()
Console.WriteLine(stack2.Count)
End Sub
End Module
|