VB.net Program to Copy Stack Elements Into an Array Using the Collection

You are currently viewing VB.net Program to Copy Stack Elements Into an Array Using the Collection

VB.Net program to copy stack elements into an array using the collection

'VB.Net program to copy stack elements into 
'an array using the collection.

Imports System
Imports System.Collections

Module Module1
    Sub Main()
        Dim stk As New Stack(5)
        Dim arr(4) As Integer

        stk.Push(40)
        stk.Push(30)
        stk.Push(20)
        stk.Push(10)

        stk.CopyTo(arr, 0)

        Console.WriteLine("Array elements are:")
        For i = 0 To 3 Step 1
            Console.WriteLine(vbTab & "Item[" & (i + 1) & "]: " & arr(i))
        Next
    End Sub
End Module
Array elements are:
        Item[1]: 10
        Item[2]: 20
        Item[3]: 30
        Item[4]: 40
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply