Stack<(Of <(T>)>) the ToArray method. : Stack « Data Structure « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Data Structure » StackScreenshots 
Stack<(Of <(T>)>) the ToArray method.
 

'Use the Push method to push five strings onto the stack. 
'The elements of the stack are enumerated, which does not change the state of the stack. 
'The Pop method is used to pop the first string off the stack. 
'The Peek method is used to look at the next item on the stack
'The ToArray method is used to create an array and copy the stack elements to it

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 * 21As String
        numbers.CopyTo(array2, numbers.Count)

        Dim stack3 As New Stack(Of String)(array2)

        Console.WriteLine("Contents of the second copy, with duplicates and nulls:")
        For Each number As String In stack3
            Console.WriteLine(number)
        Next

        Console.WriteLine("stack2.Contains(""four"") = {0}",stack2.Contains("four"))

        Console.WriteLine("stack2.Clear()")
        stack2.Clear()
        Console.WriteLine("stack2.Count = {0}",stack2.Count)
    End Sub
End Module

   
  
Related examples in the same category
1.Push Integer into a StackPush Integer into a Stack
2.Simple Demo for Stack: Push, Pop and PeekSimple Demo for Stack: Push, Pop and Peek
3.Stack to ArrayStack to Array
4.Stack Demo: push, pop and peekStack Demo: push, pop and peek
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.