Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Queue VS Queue(of T)


I will prefer yo use Queue(of T)  instead of Queue because it is type safe and second it will not cast object type  in to appropriate type so performance is better.

Queue:

Queue is non Generic Type Collection from name space(system.collection)
by default it can contain  any type  means it accept system.object(every type reference or value type derived from system.object class). Queue work on the principle of  FIFO(first in First Out) .it insert items like in array (one after other in sequence)
Module Module1
 Sub Main()
        Dim que As New Queue()
        que.Enqueue(1)
        que.Enqueue("Second")
        que.Enqueue(3)
        que.Enqueue("4th")
        Console.WriteLine("first in List")
        Console.WriteLine(que.Peek)
        que.Dequeue()
        Console.WriteLine("after deque first in List")
        Console.WriteLine(que.Peek)
        Console.ReadLine()
    End Sub
End Module


Out Put:

first in List
1
after deque first in List
Second

Queue(of T):

Queue(of T)  is  generic type collection from name space(system.collection.generic)
 it can contain a specific type means that its type safe so that you can't insert an integer and string in same list.
Dim lst As New Queue(of T)
where "T" can be integer ,string or any type.  if you will assign T as "Object" then it will work same as non generic type.Queue(of T) work on the principle of  FIFO(first in First Out) .it insert items like in array (one after other in sequence)

Module Module1

    Sub Main()
        Dim que As New Queue(Of Integer)
        que.Enqueue(1)
        que.Enqueue(2)
        que.Enqueue(3)
        que.Enqueue(4)
        Console.WriteLine("first in List")
        Console.WriteLine(que.Peek)
        que.Dequeue()
        Console.WriteLine("after deque first in List")
        Console.WriteLine(que.Peek)
        Console.ReadLine()
    End Sub
End Module

Out Put:

first in List
1
after deque first in List
2


I will prefer yo use Queue(of T)  instead of Queue because it is type safe and second it will not cast object type  in to appropriate type so performance is better .







This post first appeared on Telerik School, please read the originial post: here

Share the post

Queue VS Queue(of T)

×

Subscribe to Telerik School

Get updates delivered right to your inbox!

Thank you for your subscription

×