Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ImmutableList<T> Class

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

NuGet package: Microsoft.Bcl.Immutable (about immutable collections and how to install)

System.Object
  System.Collections.Immutable.ImmutableList<T>

Namespace:  System.Collections.Immutable
Assembly:  System.Collections.Immutable (in System.Collections.Immutable.dll)

public sealed class ImmutableList<T> : IImmutableList<T>, 
	IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, 
	IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable

Type Parameters

T

The type of elements in the list.

The ImmutableList<T> type exposes the following members.

  NameDescription
Public propertyCountGets the number of elements contained in the list.
Public propertyIsEmptyGets a value that indicates whether this list is empty.
Public propertyItemGets the element at the specified index of the list.
Top

  NameDescription
Public methodAddAdds the specified object to the end of the immutable list.
Public methodAddRangeAdds the elements of the specified collection to the end of the immutable list.
Public methodBinarySearch(T) Searches the entire sorted list for an element using the default comparer and returns the zero-based index of the element.
Public methodBinarySearch(T, IComparer<T>) Searches the entire sorted list for an element using the specified comparer and returns the zero-based index of the element.
Public methodBinarySearch(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.
Public methodClearRemoves all elements from the immutable list.
Public methodContainsDetermines whether this immutable list contains the specified value.
Public methodConvertAll<TOutput>Converts the elements in the current immutable list to another type, and returns a list containing the converted elements.
Public methodCopyTo(T[])Copies the entire immutable list to a compatible one-dimensional array, starting at the beginning of the target array.
Public methodCopyTo(T[], Int32)Copies the entire immutable list to a compatible one-dimensional array, starting at the specified index of the target array.
Public methodCopyTo(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.
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodExistsDetermines whether the immutable list contains elements that match the conditions defined by the specified predicate.
Public methodFindSearches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire immutable list.
Public methodFindAllRetrieves all the elements that match the conditions defined by the specified predicate.
Public methodFindIndex(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.
Public methodFindIndex(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.
Public methodFindIndex(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.
Public methodFindLastSearches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire immutable list.
Public methodFindLastIndex(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.
Public methodFindLastIndex(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.
Public methodFindLastIndex(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.
Public methodForEachPerforms the specified action on each element of the immutable list.
Public methodGetEnumeratorReturns an enumerator that iterates through the immutable list.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetRangeCreates a shallow copy of a range of elements in the source immutable list.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOf(T)Searches for the specified object and returns the zero-based index of the first occurrence within the entire immutable list.
Public methodIndexOf(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.
Public methodInsertInserts the specified object into the immutable list at the specified index.
Public methodInsertRangeInserts the elements of a collection into the immutable list at the specified index.
Public methodLastIndexOfSearches 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.
Public methodRemove(T)Removes the first occurrence of the specified object from this immutable list.
Public methodRemove(T, IEqualityComparer<T>)Removes the first occurrence of the object that matches the specified value from this immutable list.
Public methodRemoveAllRemoves all the elements that match the conditions defined by the specified predicate.
Public methodRemoveAtRemoves the element at the specified index.
Public methodRemoveRange(IEnumerable<T>)Removes a range of elements from this immutable list.
Public methodRemoveRange(IEnumerable<T>, IEqualityComparer<T>)Removes the specified values from this list.
Public methodRemoveRange(Int32, Int32)Removes a range of elements, starting from the specified index and containing the specified number of elements, from this immutable list.
Public methodReplace(T, T)Replaces the specified element in the immutable list with a new element.
Public methodReplace(T, T, IEqualityComparer<T>)Replaces the specified element in the immutable list with a new element.
Public methodReverse()Reverses the order of the elements in the entire immutable list.
Public methodReverse(Int32, Int32)Reverses the order of the elements in the specified range of the immutable list.
Public methodSetItemReplaces an element at a given position in the immutable list with the specified element.
Public methodSort()Sorts the elements in the entire immutable list using the default comparer.
Public methodSort(IComparer<T>)Sorts the elements in the entire immutable list using the specified comparer.
Public methodSort(Comparison<T>)Sorts the elements in the entire immutable list using the specified comparer.
Public methodSort(Int32, Int32, IComparer<T>)Sorts a range of elements in the immutable list using the specified comparer.
Public methodToBuilderCreates a list that has the same contents as this list and can be efficiently mutated across multiple operations using standard mutable interfaces.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodTrueForAllDetermines whether every element in the immutable list matches the conditions defined by the specified predicate.
Top

  NameDescription
Public Extension MethodIndexOf<T>(T)Overloaded. Searches for the specified object and returns the zero-based index of the first occurrence within the list. (Defined by ImmutableList.)
Public Extension MethodIndexOf<T>(T, IEqualityComparer<T>)Overloaded. Searches for the specified object and returns the zero-based index of the first occurrence within the list. (Defined by ImmutableList.)
Public Extension MethodIndexOf<T>(T, Int32)Overloaded. 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. (Defined by ImmutableList.)
Public Extension MethodIndexOf<T>(T, Int32, Int32)Overloaded. 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. (Defined by ImmutableList.)
Public Extension MethodLastIndexOf<T>(T)Overloaded. Searches for the specified object and returns the zero-based index of the last occurrence within the entire immutable list. (Defined by ImmutableList.)
Public Extension MethodLastIndexOf<T>(T, IEqualityComparer<T>)Overloaded. Searches for the specified object and returns the zero-based index of the last occurrence within the entire immutable list. (Defined by ImmutableList.)
Public Extension MethodLastIndexOf<T>(T, Int32)Overloaded. 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. (Defined by ImmutableList.)
Public Extension MethodLastIndexOf<T>(T, Int32, Int32)Overloaded. 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. (Defined by ImmutableList.)
Public Extension MethodRemove<T>Removes the specified value from this list. (Defined by ImmutableList.)
Public Extension MethodRemoveRange<T>Removes the specified values from this list. (Defined by ImmutableList.)
Public Extension MethodReplace<T>Replaces the first equal element in the list with the specified element. (Defined by ImmutableList.)
Public Extension MethodToImmutableArray<T> [This topic is preliminary and is subject to change.]
Creates an immutable array from the specified collection.
(Defined by ImmutableArray.)
Public Extension MethodToImmutableDictionary<T, TKey>(Func<T, TKey>)Overloaded. Constructs an immutable dictionary from an existing collection of elements, applying a transformation function to the source keys. (Defined by ImmutableDictionary.)
Public Extension MethodToImmutableDictionary<T, TKey>(Func<T, TKey>, IEqualityComparer<TKey>)Overloaded. Constructs an immutable dictionary based on some transformation of a sequence. (Defined by ImmutableDictionary.)
Public Extension MethodToImmutableDictionary<T, TKey, TValue>(Func<T, TKey>, Func<T, TValue>)Overloaded. Enumerates and transforms a sequence, and produces an immutable dictionary of its contents. (Defined by ImmutableDictionary.)
Public Extension MethodToImmutableDictionary<T, TKey, TValue>(Func<T, TKey>, Func<T, TValue>, IEqualityComparer<TKey>)Overloaded. Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key comparer. (Defined by ImmutableDictionary.)
Public Extension MethodToImmutableDictionary<T, TKey, TValue>(Func<T, TKey>, Func<T, TValue>, IEqualityComparer<TKey>, IEqualityComparer<TValue>)Overloaded. Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key and value comparers. (Defined by ImmutableDictionary.)
Public Extension MethodToImmutableHashSet<T>()Overloaded. Enumerates a sequence and produces an immutable hash set of its contents. (Defined by ImmutableHashSet.)
Public Extension MethodToImmutableHashSet<T>(IEqualityComparer<T>)Overloaded. Enumerates a sequence, produces an immutable hash set of its contents, and uses the specified equality comparer for the set type. (Defined by ImmutableHashSet.)
Public Extension MethodToImmutableList<T>Enumerates a sequence and produces an immutable list of its contents. (Defined by ImmutableList.)
Public Extension MethodToImmutableSortedDictionary<T, TKey, TValue>(Func<T, TKey>, Func<T, TValue>)Overloaded. Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents. (Defined by ImmutableSortedDictionary.)
Public Extension MethodToImmutableSortedDictionary<T, TKey, TValue>(Func<T, TKey>, Func<T, TValue>, IComparer<TKey>)Overloaded. Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents by using the specified key comparer. (Defined by ImmutableSortedDictionary.)
Public Extension MethodToImmutableSortedDictionary<T, TKey, TValue>(Func<T, TKey>, Func<T, TValue>, IComparer<TKey>, IEqualityComparer<TValue>)Overloaded. Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents by using the specified key and value comparers. (Defined by ImmutableSortedDictionary.)
Public Extension MethodToImmutableSortedSet<T>()Overloaded. Enumerates a sequence and produces an immutable sorted set of its contents. (Defined by ImmutableSortedSet.)
Public Extension MethodToImmutableSortedSet<T>(IComparer<T>)Overloaded. Enumerates a sequence, produces an immutable sorted set of its contents, and uses the specified comparer. (Defined by ImmutableSortedSet.)
Top

  NameDescription
Public fieldStatic memberEmptyGets an empty set with the default sort comparer.
Top

  NameDescription
Explicit interface implemetationPrivate methodICollection<T>.AddAdds the specified item to the immutable list.
Explicit interface implemetationPrivate methodIList.AddAdds an item to the immutable list.
Explicit interface implemetationPrivate methodICollection<T>.ClearRemoves all items from the immutable list.
Explicit interface implemetationPrivate methodIList.ClearRemoves all items from the immutable list.
Explicit interface implemetationPrivate methodIList.ContainsDetermines whether the immutable list contains a specific value.
Explicit interface implemetationPrivate methodICollection.CopyToCopies the entire immutable list to a compatible one-dimensional array, starting at the specified array index.
Explicit interface implemetationPrivate methodIEnumerable<T>.GetEnumeratorReturns an enumerator that iterates through the immutable list.
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an enumerator that iterates through the immutable list.
Explicit interface implemetationPrivate methodIList.IndexOfDetermines the index of a specific item in the immutable list.
Explicit interface implemetationPrivate methodIList<T>.InsertInserts an object in the immutable list at the specified index.
Explicit interface implemetationPrivate methodIList.InsertInserts an item into the immutable list at the specified index.
Explicit interface implemetationPrivate propertyIList.IsFixedSizeGets a value that indicates whether the list has a fixed size.
Explicit interface implemetationPrivate propertyICollection<T>.IsReadOnlyGets a value that indicates whether the list is read-only.
Explicit interface implemetationPrivate propertyIList.IsReadOnlyGets a value that indicates whether the immutable list is read-only.
Explicit interface implemetationPrivate propertyICollection.IsSynchronizedGets a value that indicates whether access to the list is synchronized.
Explicit interface implemetationPrivate propertyIList<T>.ItemGets or sets the element at the specified index.
Explicit interface implemetationPrivate propertyIList.ItemGets or sets the element at the specified index.
Explicit interface implemetationPrivate methodICollection<T>.RemoveRemoves the first occurrence of a specific object from the immutable list.
Explicit interface implemetationPrivate methodIList.RemoveRemoves the first occurrence of a specific object from the immutable list.
Explicit interface implemetationPrivate methodIList<T>.RemoveAtRemoves the value at the specified index.
Explicit interface implemetationPrivate methodIList.RemoveAtRemoves the item at the specified index of the immutable list.
Explicit interface implemetationPrivate propertyICollection.SyncRootGets an object that can be used to synchronize access to the ICollection.
Explicit interface implemetationPrivate methodIImmutableList<T>.AddAdds the specified value to this immutable list.
Explicit interface implemetationPrivate methodIImmutableList<T>.AddRangeAdds the specified values to this immutable list.
Explicit interface implemetationPrivate methodIImmutableList<T>.ClearRetrieves an empty list that has the same sorting and ordering semantics as this instance.
Explicit interface implemetationPrivate methodIImmutableList<T>.InsertInserts the specified element at the specified index in the immutable list.
Explicit interface implemetationPrivate methodIImmutableList<T>.InsertRangeInserts the specified elements at the specified index in the immutable list.
Explicit interface implemetationPrivate methodIImmutableList<T>.RemoveRemoves the element with the specified value from the list.
Explicit interface implemetationPrivate methodIImmutableList<T>.RemoveAllRemoves all the elements that match the conditions defined by the specified predicate.
Explicit interface implemetationPrivate methodIImmutableList<T>.RemoveAtRemoves the element at the specified index of the immutable list.
Explicit interface implemetationPrivate methodIImmutableList<T>.RemoveRange(IEnumerable<T>, IEqualityComparer<T>)Removes a range of elements from this immutable list that match the items specified.
Explicit interface implemetationPrivate methodIImmutableList<T>.RemoveRange(Int32, Int32)Removes the specified number of elements at the specified location from this list.
Explicit interface implemetationPrivate methodIImmutableList<T>.ReplaceReplaces an element in the list with the specified element.
Explicit interface implemetationPrivate methodIImmutableList<T>.SetItemReplaces an element in the list at a given position with the specified element.
Top

When you add or remove items from an immutable list copy of the original list is made with the items added or removed, and the original list is unchanged.

This type is thread safe.

Show:
© 2014 Microsoft