Queue<T>

Overview

Represents a first-in, first-out (FIFO) collection of objects.

Queue allows access only to first element of the collection. Queue accepts nil as a valid value for reference types and allows duplicate elements.

Note: On Nougat platform queue internally converts nil to the NSNull type.

Use case

You can use Queue class when you need to create a FIFO queue:

var Numbers := new Queue<Integer>;
Numbers.Enqueue(1);
Numbers.Enqueue(2);
Numbers.Enqueue(3);
Numbers.Enqueue(4);

writeLn(Sugar.String.Format("Current: {0}", Numbers.Dequeue));
writeLn(Sugar.String.Format("Next in queue: {0}", Numbers.Peek));  

while Numbers.Count > 0 do
  writeLn(Sugar.String.Format("Current: {0}", Numbers.Dequeue));

Output:

Current: 1
Next in queue: 2
Current: 2
Current: 3
Current: 4

Loops

Please note: Instead of using for/each or for/in loops in the collections please use ForEach methods.

For example:

var Items := new List<String>(["One", "Two", "Three"]);
Items.ForEach(item -> DoSomething(item));  

Location

 

Clear  mapped

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

Contains  mapped

 

method Contains(Item: T): Boolean

 

Boolean Contains(T Item)

 

func Contains(_ Item: T) -> Boolean

 

Boolean Contains(T Item)

Parameters:

  • Item:

Count

 

property Count: Int32 read;

 

Int32 Count { get; }

 

var Count: Int32 { get{} }

 

Int32 Count { __get; }

Dequeue  mapped

 

method Dequeue: T

 

T Dequeue()

 

func Dequeue() -> T

 

T Dequeue()

Enqueue  mapped

 

method Enqueue(Item: T)

 

void Enqueue(T Item)

 

func Enqueue(_ Item: T)

 

void Enqueue(T Item)

Parameters:

  • Item:

Peek  mapped

 

method Peek: T

 

T Peek()

 

func Peek() -> T

 

T Peek()

ToArray  mapped

 

method ToArray: array of T

 

T[] ToArray()

 

func ToArray() -> T...

 

T[] ToArray()

 

Count

 

property Count: Int32 read;

 

Int32 Count { get; }

 

var Count: Int32 { get{} }

 

Int32 Count { __get; }

 

Clear  mapped

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

Contains  mapped

 

method Contains(Item: T): Boolean

 

Boolean Contains(T Item)

 

func Contains(_ Item: T) -> Boolean

 

Boolean Contains(T Item)

Parameters:

  • Item:

Dequeue  mapped

 

method Dequeue: T

 

T Dequeue()

 

func Dequeue() -> T

 

T Dequeue()

Enqueue  mapped

 

method Enqueue(Item: T)

 

void Enqueue(T Item)

 

func Enqueue(_ Item: T)

 

void Enqueue(T Item)

Parameters:

  • Item:

Peek  mapped

 

method Peek: T

 

T Peek()

 

func Peek() -> T

 

T Peek()

ToArray  mapped

 

method ToArray: array of T

 

T[] ToArray()

 

func ToArray() -> T...

 

T[] ToArray()