Dela via


BorrowedList<TElement> Class

Definition

A collection that is optimized for adding elements to its end, and accessing them by index. BorrowedList<TElement> uses pooled arrays to store elements, which allows for frequent creation and disposal of new collections without causing GC pressure.

public sealed class BorrowedList<TElement> : IDisposable, System.Collections.Generic.ICollection<TElement>, System.Collections.Generic.IEnumerable<TElement>, System.Collections.Generic.IList<TElement>, System.Collections.Generic.IReadOnlyCollection<TElement>, System.Collections.Generic.IReadOnlyList<TElement>
type BorrowedList<'Element> = class
    interface IList<'Element>
    interface ICollection<'Element>
    interface seq<'Element>
    interface IEnumerable
    interface IReadOnlyList<'Element>
    interface IReadOnlyCollection<'Element>
    interface IDisposable
Public NotInheritable Class BorrowedList(Of TElement)
Implements ICollection(Of TElement), IDisposable, IEnumerable(Of TElement), IList(Of TElement), IReadOnlyCollection(Of TElement), IReadOnlyList(Of TElement)

Type Parameters

TElement

The type of elements in the list.

Inheritance
BorrowedList<TElement>
Implements

Remarks

The BorrowedList<TElement> internal storage is allocated in segments: a BorrowedList<TElement> containing at least one element will rent at least a segment from the pooled array (for a minimal allocation, in the current implementation of 8KB). That memory will be returned to the array pool when the BorrowedList<TElement> is disposed.

Constructors

BorrowedList<TElement>()

Creates a new instance of BorrowedList<TElement>.

BorrowedList<TElement>(IEnumerable<TElement>)

Creates a new instance of BorrowedList<TElement> which contains the elements from elements.

BorrowedList<TElement>(Int32)

Creates a new instance of BorrowedList<TElement> which contains size elements set to their default value.

Properties

Count System.Object.Count
Item[Int32]

Gets or sets the element at the specified index.

Methods

Add(TElement)

Adds an item to the ICollection<T>.

Clear()

Removes all items from the ICollection<T>.

Contains(TElement)

Determines whether the ICollection<T> contains a specific value.

CopyTo(IList<TElement>, Int32, Int32, Int32)

Copies the specified range of the BorrowedList<TElement> into buffer starting at the targetIndex position.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

GetEnumerator()

Returns an enumerator that iterates through the collection.

IndexOf(TElement)

Returns the first index of item in the BorrowedList<TElement> or -1 if item is not found.

Insert(Int32, TElement)

Inserts an item to the IList<T> at the specified index.

Remove(TElement)

Removes the first occurrence of a specific object from the ICollection<T>.

RemoveAt(Int32)

Removes the IList<T> item at the specified index.

ReplaceWith(BorrowedList<TElement>)

Replaces the current content of the BorrowedList<TElement> with the elements from other and disposes other.

ReplaceWith(IEnumerable<TElement>)

Replaces the current content of the BorrowedList<TElement> with the elements from elements.

Resize(Int32)

Resizes the BorrowedList<TElement> to contain size elements. If size is less than the current number of elements, the elements at the end of the list are removed. If size is greater than the current number of elements, the new elements are set to their default value.

Sort()

Sort the elements in the BorrowedList<TElement> using the default comparer for TElement.

Sort(Comparison<TElement>)

Sort the elements in the BorrowedList<TElement> using comparer.

Sort(IComparer<TElement>)

Sort the elements in the BorrowedList<TElement> using comparer.

Sort(Int32, Int32, Comparison<TElement>)

Sort the elements in the BorrowedList<TElement> using comparer.

Sort(Int32, Int32, IComparer<TElement>)

Sort the elements in the BorrowedList<TElement> using comparer.

Explicit Interface Implementations

ICollection<TElement>.CopyTo(TElement[], Int32)

Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.

ICollection<TElement>.IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

IEnumerable<TElement>.GetEnumerator()

Returns an enumerator that iterates through the collection.

Extension Methods

EmptyIfNull<T>(IEnumerable<T>)

Return this enumeration in case it is not null. In case it is null return empty enumeration.

Applies to