ImmutableList<T> 类

定义

表示一个不可变列表,该列表是可按索引访问的对象的强类型列表。Represents an immutable list, which is a strongly typed list of objects that can be accessed by index.

NuGet 包System.Collections.Immutable关于不可变集合和安装方法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)

类型参数

T

列表中元素的类型。The type of elements in the list.

继承
ImmutableList<T>
实现

注解

ImmutableList<T> 没有公共构造函数;首先,使用 ImmutableList<T>.Empty 检索空 ImmutableList<T>ImmutableList<T> has no public constructor; you begin by retrieving an empty ImmutableList<T> by using the ImmutableList<T>.Empty. 然后,可以调用方法(如 AddAddRange)来填充集合。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.

字段

Empty

获取使用默认排序比较器的空集。Gets an empty set with the default sort comparer.

属性

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.

方法

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.

(继承自 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.

(继承自 Object)
GetRange(Int32, Int32)

在源不可变列表中创建元素范围的浅表复制。Creates a shallow copy of a range of elements in the source immutable list.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 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)

获取对给定 index 处的集元素的只读引用。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()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 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.

(继承自 Object)
TrueForAll(Predicate<T>)

确定不可变列表中的每个元素是否都与指定谓词定义的条件匹配。Determines whether every element in the immutable list matches the conditions defined by the specified predicate.

显式界面实现

ICollection.CopyTo(Array, Int32)

从指定的数组索引处开始,将整个不可变列表复制到兼容的一维目标数组。Copies the entire immutable list to a compatible one-dimensional array, starting at the specified array index.

ICollection.IsSynchronized

请参阅 ICollection 接口。See the ICollection interface.

ICollection.SyncRoot

请参阅 ICollectionSee 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

获取一个值,该值指示 ICollection<T> 是否为只读。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

获取一个值,该值指示 IList 是否具有固定大小。Gets a value indicating whether the IList has a fixed size.

IList.IsReadOnly

获取一个值,该值指示 ICollection<T> 是否为只读。Gets a value indicating whether the ICollection<T> is read-only.

IList.Item[Int32]

获取或设置指定索引处的 ObjectGets 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.

扩展方法

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>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRowReturns 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)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies 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)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts 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. 集合中仅包括具有匹配 XName 的元素。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. 集合中仅包括具有匹配 XName 的元素。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. 集合中仅包括具有匹配 XName 的元素。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.

适用于

线程安全性

此类型是线程安全的。This type is thread safe.