Home »
VB.Net »
VB.Net Programs
VB.Net program to count the total items in Queue collection
By Nidhi Last Updated : October 13, 2024
Count the total items in a Queue in VB.Net
Here, we will use the Count property of the Queue collection class and print the count of items on the console screen.
Program/Source Code:
The source code to count the total items in the Queue collection is given below. The given program is compiled and executed successfully.
VB.Net code to count the total items in Queue collection
'VB.Net program to count the total items in Queue collection.
Imports System
Imports System.Collections
Module Module1
Sub Main()
Dim queue As New Queue(5)
queue.Enqueue("India")
queue.Enqueue("USA")
queue.Enqueue("UK")
queue.Enqueue("CHINA")
Console.WriteLine("Total items in queue are: " & queue.Count)
End Sub
End Module
Output
Total items in queue 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, And, we created an object of the Queue collection class for 5 elements. After that, we inserted 4 items using the Enqueue() method and then count the total items of the queue using the Count property and printed the item count on the console screen.
VB.Net Data Structure Programs »