C# Queue TrimExcess
Description
Queue
sets the capacity to the actual
number of elements in the Queue
Syntax
Queue.TrimExcess
has the following syntax.
public void TrimExcess()
Returns
Queue.TrimExcess
method returns
Example
//from w w w . j av a2 s. c o m
using System;
using System.Collections.Generic;
class Example
{
public static void Main()
{
Queue<string> numbers = new Queue<string>();
numbers.Enqueue("one");
numbers.Enqueue("two");
numbers.Enqueue("three");
numbers.Enqueue("four");
numbers.Enqueue("five");
numbers.TrimExcess();
foreach( string number in numbers )
{
Console.WriteLine(number);
}
}
}
The code above generates the following result.