# `Deque` Class ## Definition Represents a double-ended queue for which elements can be added to or removed from the front or back. ```cs public class Deque : ICollection, ICollection, IDeque, IEnumerable, IEnumerable, IList, IList, IReadOnlyCollection, IReadOnlyDeque, IReadOnlyList; ``` Inheritance: Object → Deque<T> Implements: ICollection, ICollection<T>, IDeque<T>, IEnumerable, IEnumerable<T>, IList, IList<T>, IReadOnlyCollection<T>, IReadOnlyDeque<T>, IReadOnlyList<T> ### Type params `T` : The type of elements in the [Deque<T>](./Deque~T~--Class.md). ## Remarks This supports random-access to the elements contained in the collection and addition of elements to the front or back, or removal from the front or back. ## Constructors | Constructor signature | Summary | | :--------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Deque() | Initializes a new instance of the [Deque<T>][deque] class. | | Deque(int) | Initializes a new instance of the [Deque<T>][deque] class that is empty and has the specified initial capacity. | | Deque(IEnumerable<T>) | Initializes a new instance of the [Deque<T>][deque] class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied. | | Deque(ReadOnlySpan<T>) | Initializes a new instance of the [Deque<T>][deque] class that contains elements copied from the specified span and has sufficient capacity to accommodate the number of the elements copied. | ## Properties | Property name | Summary | | :------------ | :------------------------------------------------------------------------------------------------------------------------------------------ | | this\[int\] | Gets or sets the element at the specified index. | | Capacity | Gets the number of total elements the [Deque<T>][deque] can hold without resizing. | | Count | Gets the number of the elements contained in the [Deque<T>][deque]. | | FrontMargin | Gets the number of elements that can be added at the beginning of the [Deque<T>][deque] without resizing the internal data structure. | | IsEmpty | Gets the value that indicates whether the [Deque<T>][deque] is empty. | | LastMargin | Gets the number of elements that can be added at the end of the [Deque<T>][deque] without resizing the internal data structure. | ## Methods | Method name | Summary | | :-------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | AsReadOnlySpan() | Creates a new read-only span over the [Deque<T>][deque]. | | Clear() | Removes all of the elements from the [Deque<T>][deque]. | | Contains(T) | Determines whether the [Deque<T>][deque] contains a specific value. | | CopyTo(T\[\], int) | Copies the elements of the [Deque<T>][deque] to an `T`\[\], starting at a particular index. | | EnsureCapacity(int) | Ensures that the capacity of this [Deque<T>][deque] is at least the specified one. | | EnsureCapacity(int, int) | Ensures that the margins at the beginning and back of the [Deque<T>][deque] are respectively at least those specified. | | Find(Predicate<T>) | Searches for the first element that matches the conditions defined by the specified Predicate<T>. | | FindLast(Predicate<T>) | Searches for the last element that matches the conditions defined by the specified Predicate<T>. | | GetEnumerator() | Returns an enumerator that iterates through the [Deque<T>][deque]. | | IndexOf(T) | Searches for the specified item and returns the zero-based index of the first occurrence within the entire [Deque<T>][deque]. | | Insert(int, T) | Inserts an item to the [Deque<T>][deque] at the specified index. | | InsertRange(int, IEnumerable<T>) | Inserts the elements of the specified collection into the [Deque<T>][deque] at the specified index. | | InsertRange(int, ReadOnlySpan<T>) | Inserts the elements of the specified span into the [Deque<T>][deque] at the specified index. | | LastIndexOf(T) | Searches for the specified item and returns the zero-based index of the last occurrence within the entire [Deque<T>][deque]. | | PeekFirst() | Returns the object at the beginning of the [Deque<T>][deque] without removing it. | | PeekLast() | Returns the object at the end of the [Deque<T>][deque] without removing it. | | PopBack() | Removes and returns the object at the end of the [Deque<T>][deque]. | | PopBackRange(int) | Removes and returns the specified number of objects at the end of the [Deque<T>][deque]. | | PopBackRange(Span<T>) | Removes the certain number of objects at the end of the [Deque<T>][deque] and copies them to the specified span to fill up it. | | PopFront() | Removes and returns the object at the beginning of the [Deque<T>][deque]. | | PopFrontRange(int) | Removes and returns the specified number of objects at the beginning of the [Deque<T>][deque]. | | PopFrontRange(Span<T>) | Removes the certain number of objects at the beginning of the [Deque<T>][deque] and copies them to the specified span to fill up it. | | PushBack(T) | Adds an object to the end of the [Deque<T>][deque]. | | PushBackRange(IEnumerable<T>) | Adds the elements of the specified collection to the end of the [Deque<T>][deque]. | | PushBackRange(ReadOnlySpan<T>) | Adds the elements of the specified memory region to the end of the [Deque<T>][deque]. | | PushFront(T) | Adds an object to the beginning of the [Deque<T>][deque]. | | PushFrontRange(IEnumerable<T>) | Adds the elements of the specified collection to the beginning of the [Deque<T>][deque]. | | PushFrontRange(ReadOnlySpan<T>) | Adds the elements of the specified memory region to the beginning of the [Deque<T>][deque]. | | Remove(T) | Removes the first occurrence of the specified object from the [Deque<T>][deque]. | | RemoveAt(int) | Removes the element at the specified index. | | RemoveRange(int, int) | Removes a range of elements from the [Deque<T>][deque]. | | Resize(int) | Resizes the internal array to the specified size. | | ShrinkToFit() | Shrink the internal data structure so that the [Deque<T>][deque] doesn't have any margin at the beginning or end of it. | | TryPeekFirst(out T) | Returns a value that indicates whether there is an object at the beginning of the [Deque<T>][deque], and if one is present, copies it to the `item` parameter. | | TryPeekLast(out T) | Returns a value that indicates whether there is an object at the end of the [Deque<T>][deque], and if one is present, copies it to the `item` parameter. | | TryPopBack(out T) | Returns a value that indicates whether there is an object at the end of the [Deque<T>][deque], and if one is present, copies it to the `item` parameter and removes it from the [Deque<T>][deque]. | | TryPopFront(out T) | Returns a value that indicates whether there is an object at the beginning of the [Deque<T>][deque], and if one is present, copies it to the `item` parameter and removes it from the [Deque<T>][deque]. | ## Explicit Interface Implementations | Member name | Summary | | :----------------------------------- | :---------------------------------------------------------------------------------------- | | ICollection.CopyTo(Array, int) | Copies the elements of the ICollection to an Array, starting at a particular Array index. | | ICollection.IsSynchronized | Gets a value indicating whether access to the ICollection is synchronized (thread safe). | | ICollection.SyncRoot | Gets an object that can be used to synchronize access to the ICollection. | | ICollection<T>.Add(T) | | | ICollection<T>.IsReadOnly | Gets a value indicating whether the ICollection<T> is read-only. | | IEnumerable.GetEnumerator() | Returns an enumerator that iterates through a collection. | | IEnumerable<T>.GetEnumerator() | Returns an enumerator that iterates through a collection. | | IList.Add(object) | Adds an item to the IList. | | IList.Contains(object) | Determines whether the IList contains a specific value. | | IList.IndexOf(object) | Determines the index of a specific item in the IList. | | IList.Insert(int, object) | Inserts an item to the IList at the specified index. | | IList.IsFixedSize | Gets a value indicating whether the IList has a fixed size. | | IList.IsReadOnly | Gets a value indicating whether the IList is read-only. | | IList.Remove(object) | Removes the first occurrence of a specific object from the IList. | | IList.this\[int\] | Gets or sets the element at the specified index. | --- [deque]: <./Deque~T~--Class.md>