Home »
VB.Net »
VB.Net Programs
VB.Net program to delete all items from the stack using Collection
By Nidhi Last Updated : November 11, 2024
Delete all items from stack in VB.Net
Here, we will use the Clear() method of the Stack collection class to remove all items from the stack.
Program/Source Code:
The source code to delete all items from the stack using Collection is given below. The given program is compiled and executed successfully.
VB.Net code to delete all items from the stack using Collection
'VB.Net program to delete all items from
'the stack using Collection.
Imports System
Imports System.Collections
Module Module1
Sub Main()
Dim stk As New Stack(5)
stk.Push(40)
stk.Push(30)
stk.Push(20)
stk.Push(10)
stk.Clear()
Console.WriteLine("Now all items are deleted from stack")
End Sub
End Module
Output
Now all items are deleted from stack
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program, Here, we created an object of Stack collection class for 5 elements. After that we inserted 4 items using the Push() method into the stack and then delete all inserted items from the stack using the Clear() method of Stack class and then print "Now all items are deleted from stack" on the console screen.
VB.Net Data Structure Programs »