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.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.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
5.Stack Class represents a simple last-in-first-out (LIFO) non-generic collection of objects.
ww___w.__ja___v__a__2_s._c___o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.