VB.Net program to convert the Stack collection into an Object array

Here, we are going to learn how to convert the Stack collection into an Object array in VB.Net?
Submitted by Nidhi, on January 17, 2021

Here, we will use ToArray() method of Stack collection to covert the Stack into the Object array and print the Object array elements on the console screen.

Program/Source Code:

The source code to convert the Stack collection into an Object array is given below. The given program is compiled and executed successfully.

'VB.Net program to convert the Stack collection 
'into an Object array.

Imports System
Imports System.Collections

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


        arr = stk.ToArray()

        Console.WriteLine("Object Array elements are:")
        For i = 0 To 3 Step 1
            Console.WriteLine(vbTab & "Item[" & (i + 1) & "]: " & arr(i))
    End Sub
End Module


Object Array elements are:
        Item[1]: CHINA
        Item[2]: UK
        Item[3]: USA
        Item[4]: India
Press any key to continue . . .


In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program, And, we created an object of Stack collection class for 5 elements. After that, we inserted 4 items using the Push() method and then converted the Stack collection into the object array, and then printed the elements of the object array on the console screen.

VB.Net Data Structure Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.