×

VB.Net Programs

VB.Net program to get the total number of items in the STACK using the collection

By Nidhi Last Updated : November 15, 2024

Find the total items of a stack in VB.Net

Here, we will use the Count property of the Stack collection class to get the total number of items available in the STACK collection.

Program/Source Code:

The source code to get the total number of items in the STACK using collection is given below. The given program is compiled and executed successfully.

VB.Net code to find the total items of a stack in VB.Net

'VB.Net program to get the total number of items in 
'the STACK using the 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)

        Console.WriteLine("Number of items in STACK are: " & stk.Count)
    End Sub
End Module

Output

Number of items in STACK are: 4
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 get the count of available items using the Count property of the collection class and print the count on the console screen.

VB.Net Data Structure Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.