
- VB.Net Basic Tutorial
- VB.Net - Home
- VB.Net - Overview
- VB.Net - Environment Setup
- VB.Net - Program Structure
- VB.Net - Basic Syntax
- VB.Net - Data Types
- VB.Net - Variables
- VB.Net - Constants
- VB.Net - Modifiers
- VB.Net - Statements
- VB.Net - Directives
- VB.Net - Operators
- VB.Net - Decision Making
- VB.Net - Loops
- VB.Net - Strings
- VB.Net - Date & Time
- VB.Net - Arrays
- VB.Net - Collections
- VB.Net - Functions
- VB.Net - Subs
- VB.Net - Classes & Objects
- VB.Net - Exception Handling
- VB.Net - File Handling
- VB.Net - Basic Controls
- VB.Net - Dialog Boxes
- VB.Net - Advanced Forms
- VB.Net - Event Handling
- VB.Net Advanced Tutorial
- VB.Net - Regular Expressions
- VB.Net - Database Access
- VB.Net - Excel Sheet
- VB.Net - Send Email
- VB.Net - XML Processing
- VB.Net - Web Programming
- VB.Net Useful Resources
- VB.Net - Quick Guide
- VB.Net - Useful Resources
- VB.Net - Discussion
VB.Net - Queue
It represents a first-in, first-out collection of object. It is used when you need a first-in, first-out access of items. When you add an item in the list, it is called enqueue, and when you remove an item, it is called deque.
Properties and Methods of the Queue Class
The following table lists some of the commonly used properties of the Queue class −
Sr.No | Property & Description |
---|---|
1 | Count Gets the number of elements contained in the Queue. |
The following table lists some of the commonly used methods of the Queue class −
Sr.No. | Method Name & Purpose |
---|---|
1 |
Public Overridable Sub Clear Removes all elements from the Queue. |
2 |
Public Overridable Function Contains (obj As Object) As Boolean Determines whether an element is in the Queue. |
3 |
Public Overridable Function Dequeue As Object Removes and returns the object at the beginning of the Queue. |
4 |
Public Overridable Sub Enqueue (obj As Object) Adds an object to the end of the Queue. |
5 |
Public Overridable Function ToArray As Object() Copies the Queue to a new array. |
6 |
Public Overridable Sub TrimToSize Sets the capacity to the actual number of elements in the Queue. |
Example
The following example demonstrates use of Queue −
Module collections Sub Main() Dim q As Queue = New Queue() q.Enqueue("A") q.Enqueue("M") q.Enqueue("G") q.Enqueue("W") Console.WriteLine("Current queue: ") Dim c As Char For Each c In q Console.Write(c + " ") Next c Console.WriteLine() q.Enqueue("V") q.Enqueue("H") Console.WriteLine("Current queue: ") For Each c In q Console.Write(c + " ") Next c Console.WriteLine() Console.WriteLine("Removing some values ") Dim ch As Char ch = q.Dequeue() Console.WriteLine("The removed value: {0}", ch) ch = q.Dequeue() Console.WriteLine("The removed value: {0}", ch) Console.ReadKey() End Sub End Module
When the above code is compiled and executed, it produces the following result −
Current queue: A M G W Current queue: A M G W V H Removing some values The removed value: A The removed value: M