Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

Stack.CopyTo Method

Class

System.Collections.Stack

Syntax

                  stackvariable.CopyTo(array, index)
array (required; Array of Objects)

Array to which to copy the stack’s objects

index (required; Integer)

The index of the first array element to receive an element of the stack

Return Value

None

Description

Copies the stack elements into an array, starting at a specified array index

Rules at a Glance

  • The array can be of any data type that is compatible with the stack elements. Thus, for instance, we cannot use an Integer array to hold stack elements that are strings (that is, Objects whose subtype is String).

  • The array must be sized to accommodate the elements of the stack prior to calling the CopyTo method.

Example

Public Sub Main

' Define a new stack
Dim s As New Stack(  )
Dim aStack(  ), oItem As Object

' Push some items onto stack
s.Push("Chopin")
s.Push("Mozart")
s.Push("Beethoven")

' Size the array and copy to it
Redim aStack(s.Count - 1)
s.CopyTo(aStack, 0)

For Each oItem in aStack
   Console.WriteLine(oItem)
Next

End Sub
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata