ImmutableList<T> Class

Definition

Represents an immutable list, which is a strongly typed list of objects that can be accessed by index.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

generic <typename T>
public ref class ImmutableList sealed : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IList<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::Generic::IReadOnlyList<T>, System::Collections::IList, System::Collections::Immutable::IImmutableList<T>
public sealed class ImmutableList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.IReadOnlyList<T>, System.Collections.IList, System.Collections.Immutable.IImmutableList<T>
type ImmutableList<'T> = class
    interface ICollection<'T>
    interface seq<'T>
    interface IEnumerable
    interface IList<'T>
    interface IReadOnlyCollection<'T>
    interface IReadOnlyList<'T>
    interface ICollection
    interface IList
    interface IImmutableList<'T>
Public NotInheritable Class ImmutableList(Of T)
Implements ICollection(Of T), IEnumerable(Of T), IImmutableList(Of T), IList, IList(Of T), IReadOnlyCollection(Of T), IReadOnlyList(Of T)

Type Parameters

T

The type of elements in the list.

Inheritance
ImmutableList<T>
Implements

Remarks

ImmutableList<T> has no public constructor; you begin by retrieving an empty ImmutableList<T> by using the ImmutableList<T>.Empty. You can then call methods, such as Add and AddRange, to populate the collection. Note that these methods return a new object. When you add or remove items from an immutable list, a copy of the original list is made with the items added or removed, and the original list is unchanged.

Fields

Empty

Gets an empty set with the default sort comparer.

Properties

Count

Gets the number of elements contained in the list.

IsEmpty

Gets a value that indicates whether this list is empty.

Item[Int32]

Gets the element at the specified index of the list.

Methods

Add(T)

Adds the specified object to the end of the immutable list.

AddRange(IEnumerable<T>)

Adds the elements of the specified collection to the end of the immutable list.

BinarySearch(Int32, Int32, T, IComparer<T>)

Searches a range of elements in the sorted list for an element using the specified comparer and returns the zero-based index of the element.

BinarySearch(T)

Searches the entire sorted list for an element using the default comparer and returns the zero-based index of the element.

BinarySearch(T, IComparer<T>)

Searches the entire sorted list for an element using the specified comparer and returns the zero-based index of the element.

Clear()

Removes all elements from the immutable list.

Contains(T)

Determines whether this immutable list contains the specified value.

ConvertAll<TOutput>(Func<T,TOutput>)

Converts the elements in the current immutable list to another type, and returns a list containing the converted elements.

CopyTo(Int32, T[], Int32, Int32)

Copies a range of elements from the immutable list to a compatible one-dimensional array, starting at the specified index of the target array.

CopyTo(T[])

Copies the entire immutable list to a compatible one-dimensional array, starting at the beginning of the target array.

CopyTo(T[], Int32)

Copies the entire immutable list to a compatible one-dimensional array, starting at the specified index of the target array.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Exists(Predicate<T>)

Determines whether the immutable list contains elements that match the conditions defined by the specified predicate.

Find(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire immutable list.

FindAll(Predicate<T>)

Retrieves all the elements that match the conditions defined by the specified predicate.

FindIndex(Int32, Int32, Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the immutable list that starts at the specified index and contains the specified number of elements.

FindIndex(Int32, Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the immutable list that extends from the specified index to the last element.

FindIndex(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the entire immutable list.

FindLast(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire immutable list.

FindLastIndex(Int32, Int32, Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the immutable list that contains the specified number of elements and ends at the specified index.

FindLastIndex(Int32, Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the immutable list that extends from the first element to the specified index.

FindLastIndex(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the entire immutable list.

ForEach(Action<T>)

Performs the specified action on each element of the immutable list.

GetEnumerator()

Returns an enumerator that iterates through the immutable list.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetRange(Int32, Int32)

Creates a shallow copy of a range of elements in the source immutable list.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(T)

Searches for the specified object and returns the zero-based index of the first occurrence within the entire immutable list.

IndexOf(T, Int32, Int32, IEqualityComparer<T>)

Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the list that starts at the specified index and contains the specified number of elements.

Insert(Int32, T)

Inserts the specified object into the immutable list at the specified index.

InsertRange(Int32, IEnumerable<T>)

Inserts the elements of a collection into the immutable list at the specified index.

ItemRef(Int32)

Gets a read-only reference to the element of the set at the given index.

LastIndexOf(T, Int32, Int32, IEqualityComparer<T>)

Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the list that contains the specified number of elements and ends at the specified index.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(T)

Removes the first occurrence of the specified object from this immutable list.

Remove(T, IEqualityComparer<T>)

Removes the first occurrence of the object that matches the specified value from this immutable list.

RemoveAll(Predicate<T>)

Removes all the elements that match the conditions defined by the specified predicate.

RemoveAt(Int32)

Removes the element at the specified index.

RemoveRange(IEnumerable<T>)

Removes a range of elements from this immutable list.

RemoveRange(IEnumerable<T>, IEqualityComparer<T>)

Removes the specified values from this list.

RemoveRange(Int32, Int32)

Removes a range of elements, starting from the specified index and containing the specified number of elements, from this immutable list.

Replace(T, T)

Replaces the specified element in the immutable list with a new element.

Replace(T, T, IEqualityComparer<T>)

Replaces the specified element in the immutable list with a new element.

Reverse()

Reverses the order of the elements in the entire immutable list.

Reverse(Int32, Int32)

Reverses the order of the elements in the specified range of the immutable list.

SetItem(Int32, T)

Replaces an element at a given position in the immutable list with the specified element.

Sort()

Sorts the elements in the entire immutable list using the default comparer.

Sort(Comparison<T>)

Sorts the elements in the entire immutable list using the specified comparer.

Sort(IComparer<T>)

Sorts the elements in the entire immutable list using the specified comparer.

Sort(Int32, Int32, IComparer<T>)

Sorts a range of elements in the immutable list using the specified comparer.

ToBuilder()

Creates a list that has the same contents as this list and can be efficiently mutated across multiple operations using standard mutable interfaces.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
TrueForAll(Predicate<T>)

Determines whether every element in the immutable list matches the conditions defined by the specified predicate.

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

Copies the entire immutable list to a compatible one-dimensional array, starting at the specified array index.

ICollection.IsSynchronized

See the ICollection interface.

ICollection.SyncRoot

See ICollection.

ICollection<T>.Add(T)

Adds the specified item to the immutable list.

ICollection<T>.Clear()

Removes all items from the immutable list.

ICollection<T>.IsReadOnly

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

ICollection<T>.Remove(T)

Removes the first occurrence of a specific object from the immutable list.

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through the immutable list.

IEnumerable<T>.GetEnumerator()

Returns an enumerator that iterates through the immutable list.

IImmutableList<T>.Add(T)

Adds the specified value to this immutable list.

IImmutableList<T>.AddRange(IEnumerable<T>)

Adds the specified values to this immutable list.

IImmutableList<T>.Clear()

Retrieves an empty list that has the same sorting and ordering semantics as this instance.

IImmutableList<T>.Insert(Int32, T)

Inserts the specified element at the specified index in the immutable list.

IImmutableList<T>.InsertRange(Int32, IEnumerable<T>)

Inserts the specified elements at the specified index in the immutable list.

IImmutableList<T>.Remove(T, IEqualityComparer<T>)

Removes the element with the specified value from the list.

IImmutableList<T>.RemoveAll(Predicate<T>)

Removes all the elements that match the conditions defined by the specified predicate.

IImmutableList<T>.RemoveAt(Int32)

Removes the element at the specified index of the immutable list.

IImmutableList<T>.RemoveRange(IEnumerable<T>, IEqualityComparer<T>)

Removes a range of elements from this immutable list that match the items specified.

IImmutableList<T>.RemoveRange(Int32, Int32)

Removes the specified number of elements at the specified location from this list.

IImmutableList<T>.Replace(T, T, IEqualityComparer<T>)

Replaces an element in the list with the specified element.

IImmutableList<T>.SetItem(Int32, T)

Replaces an element in the list at a given position with the specified element.

IList.Add(Object)

Adds an item to the immutable list.

IList.Clear()

Removes all items from the immutable list.

IList.Contains(Object)

Determines whether the immutable list contains a specific value.

IList.IndexOf(Object)

Determines the index of a specific item in the immutable list.

IList.Insert(Int32, Object)

Inserts an item into the immutable list 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 ICollection<T> is read-only.

IList.Item[Int32]

Gets or sets the Object at the specified index.

IList.Remove(Object)

Removes the first occurrence of a specific object from the immutable list.

IList.RemoveAt(Int32)

Removes the item at the specified index of the immutable list.

IList<T>.Insert(Int32, T)

Inserts an object in the immutable list at the specified index.

IList<T>.Item[Int32]

Gets or sets the value at the specified index.

IList<T>.RemoveAt(Int32)

Removes the value at the specified index.

Extension Methods

IndexOf<T>(IImmutableList<T>, T)

Searches for the specified object and returns the zero-based index of the first occurrence within the list.

IndexOf<T>(IImmutableList<T>, T, IEqualityComparer<T>)

Searches for the specified object and returns the zero-based index of the first occurrence within the list.

IndexOf<T>(IImmutableList<T>, T, Int32)

Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the immutable list that extends from the specified index to the last element.

IndexOf<T>(IImmutableList<T>, T, Int32, Int32)

Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the immutable list that extends from the specified index to the last element.

LastIndexOf<T>(IImmutableList<T>, T)

Searches for the specified object and returns the zero-based index of the last occurrence within the entire immutable list.

LastIndexOf<T>(IImmutableList<T>, T, IEqualityComparer<T>)

Searches for the specified object and returns the zero-based index of the last occurrence within the entire immutable list.

LastIndexOf<T>(IImmutableList<T>, T, Int32)

Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the immutable list that extends from the first element to the specified index.

LastIndexOf<T>(IImmutableList<T>, T, Int32, Int32)

Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the immutable list that extends from the first element to the specified index.

Remove<T>(IImmutableList<T>, T)

Removes the specified value from this list.

RemoveRange<T>(IImmutableList<T>, IEnumerable<T>)

Removes the specified values from this list.

Replace<T>(IImmutableList<T>, T, T)

Replaces the first equal element in the list with the specified element.

CopyToDataTable<T>(IEnumerable<T>)

Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>)

Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the ancestors of every node in the source collection. Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>)

Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>)

Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>)

Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName)

Returns a filtered collection of the child elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>)

Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>)

Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>)

Removes every node in the source collection from its parent node.

Applies to

Thread Safety

This type is thread safe.