Queue represents a first-in, first out collection of object. It is used when you need a first-in, first-out access to items. When you add an item in the list, it is called enqueue, and when you remove an item, it is called Dequeue.
Queue<T>.TrimExcess Method is used to set the capacity to the actual number of elements in the Queue<T>, if that number is less than 90 percent of current capacity.
A queue is an unbounded data structure and there is no method available to calculate the capacity of Queue in C#. It is dynamic and depends on the system memory. This method is generally used in memory management of the large queue.
- Enqueue adds an element to the end of the Queue.
- Dequeue removes the oldest element from the start of the Queue.
- Peek returns the oldest element that is at the start of the Queue but does not remove it from the Queue.
- The capacity of a Queue is the number of elements the Queue can hold.
- As elements are added to a Queue, the capacity is automatically increased as required by reallocating the internal array.
- Queue accepts null as a valid value for reference types and allows duplicate elements.
public void TrimExcess ();
- This method can be used to minimize a collection’s memory overhead if no new elements will be added to the collection.
- To reset a Queue<T> to its initial state, call the Clear method before calling the TrimExcess method.
- Trimming an empty Queue<T> sets the capacity of the Queue<T> to the default capacity.
Below given is an example to understand the implementation in a better way:
- MathF.Log() Method in C# with Examples
- MathF.Cos() Method in C# with Examples
- MathF.Exp() Method in C# with Examples
- MathF.Max() Method in C# with Examples
- MathF.Min() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- MathF.Pow() Method in C# with Examples
- MathF.Abs() Method in C# with Examples
- MathF.Tan() Method in C# with Examples
- MathF.Round() Method in C# with Examples | Set - 2
- MathF.Round() Method in C# with Examples | Set - 1
- SByte.GetHashCode Method in C# with Examples
- SByte.Equals Method in C# with Examples
- SByte.CompareTo() Method in C# with Examples
- MathF.Tanh() Method in C# with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.