ImmutableDictionary<TKey,TValue> 类

定义

表示键和值的不可变未排序集合。Represents an immutable, unordered collection of keys and values.

NuGet 包System.Collections.Immutable关于不可变集合和安装方法NuGet package: System.Collections.Immutable (about immutable collections and how to install)

generic <typename TKey, typename TValue>
public ref class ImmutableDictionary sealed : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IDictionary<TKey, TValue>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IReadOnlyCollection<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IReadOnlyDictionary<TKey, TValue>, System::Collections::IDictionary, System::Collections::Immutable::IImmutableDictionary<TKey, TValue>
public sealed class ImmutableDictionary<TKey,TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IDictionary<TKey,TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey,TValue>, System.Collections.IDictionary, System.Collections.Immutable.IImmutableDictionary<TKey,TValue>
type ImmutableDictionary<'Key, 'Value> = class
    interface ICollection<KeyValuePair<'Key, 'Value>>
    interface seq<KeyValuePair<'Key, 'Value>>
    interface IEnumerable
    interface IDictionary<'Key, 'Value>
    interface IReadOnlyCollection<KeyValuePair<'Key, 'Value>>
    interface IReadOnlyDictionary<'Key, 'Value>
    interface ICollection
    interface IDictionary
    interface IImmutableDictionary<'Key, 'Value>
Public NotInheritable Class ImmutableDictionary(Of TKey, TValue)
Implements ICollection(Of KeyValuePair(Of TKey, TValue)), IDictionary, IDictionary(Of TKey, TValue), IEnumerable(Of KeyValuePair(Of TKey, TValue)), IImmutableDictionary(Of TKey, TValue), IReadOnlyCollection(Of KeyValuePair(Of TKey, TValue)), IReadOnlyDictionary(Of TKey, TValue)

类型参数

TKey

字典中的键的类型。The type of the keys in the dictionary.

TValue

字典中的值的类型。The type of the values in the dictionary.

继承
ImmutableDictionary<TKey,TValue>
实现

注解

操作不可变字典时,将生成原始字典的副本,应用操作并返回新的不可变字典。When you manipulate an immutable dictionary a copy of the original dictionary is made, manipulations applied and a new immutable dictionary is returned.

字段

Empty

获取空的不可变字典。Gets an empty immutable dictionary.

属性

Count

获取不可变字典中键/值对的数目。Gets the number of key/value pairs in the immutable dictionary.

IsEmpty

获取一个值,该值指示此不可变字典实例是否为空。Gets a value that indicates whether this instance of the immutable dictionary is empty.

Item[TKey]

获取与指定键关联的 TValueGets the TValue associated with the specified key.

KeyComparer

获取不可变字典的键比较器。Gets the key comparer for the immutable dictionary.

Keys

获取不可变字典中的键。Gets the keys in the immutable dictionary.

ValueComparer

获取用于确定值是否相等的值比较器。Gets the value comparer used to determine whether values are equal.

Values

获取不可变字典中的值。Gets the values in the immutable dictionary.

方法

Add(TKey, TValue)

将具有指定键和值的元素添加到不可变字典。Adds an element with the specified key and value to the immutable dictionary.

AddRange(IEnumerable<KeyValuePair<TKey,TValue>>)

将指定的键/值对添加到不可变字典。Adds the specified key/value pairs to the immutable dictionary.

Clear()

检索排序规则和键/值比较规则与此字典实例相同的空不可变字典。Retrieves an empty immutable dictionary that has the same ordering and key/value comparison rules as this dictionary instance.

Contains(KeyValuePair<TKey,TValue>)

确定此不可变字典是否包含指定的键/值对。Determines whether this immutable dictionary contains the specified key/value pair.

ContainsKey(TKey)

确定不可变字典是否包含具有指定键的元素。Determines whether the immutable dictionary contains an element with the specified key.

ContainsValue(TValue)

确定不可变字典是否包含具有指定值的元素。Determines whether the immutable dictionary contains an element with the specified value.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEnumerator()

返回一个循环访问不可变字典的枚举器。Returns an enumerator that iterates through the immutable dictionary.

GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
Remove(TKey)

从不可变字典中移除具有指定键的元素。Removes the element with the specified key from the immutable dictionary.

RemoveRange(IEnumerable<TKey>)

从不可变字典中移除具有指定键的元素。Removes the elements with the specified keys from the immutable dictionary.

SetItem(TKey, TValue)

在不可变字典中设置指定的键和值,可能的设置方法是覆盖该键的现有值。Sets the specified key and value in the immutable dictionary, possibly overwriting an existing value for the key.

SetItems(IEnumerable<KeyValuePair<TKey,TValue>>)

在不可变字典中设置指定的键/值对,可能的设置方法是覆盖键的现有值。Sets the specified key/value pairs in the immutable dictionary, possibly overwriting existing values for the keys.

ToBuilder()

创建一个其内容与此字典相同,并且可使用标准可变接口在多个操作之间有效转变的不可变字典。Creates an immutable dictionary with the same contents as this dictionary that can be efficiently mutated across multiple operations by using standard mutable interfaces.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
TryGetKey(TKey, TKey)

确定此字典是否包含指定的键。Determines whether this dictionary contains a specified key.

TryGetValue(TKey, TValue)

获取与指定键关联的值。Gets the value associated with the specified key.

WithComparers(IEqualityComparer<TKey>)

获取使用指定键比较器的不可变字典实例。Gets an instance of the immutable dictionary that uses the specified key comparer.

WithComparers(IEqualityComparer<TKey>, IEqualityComparer<TValue>)

获取使用指定键和值比较器的不可变字典实例。Gets an instance of the immutable dictionary that uses the specified key and value comparers.

显式界面实现

ICollection.CopyTo(Array, Int32)

从特定的数组索引开始,将字典的元素复制到数组中。Copies the elements of the dictionary to an array, starting at a particular array index.

ICollection.IsSynchronized

获取一个值,该值指示是否同步对 ICollection 的访问(线程安全)。Gets a value indicating whether access to the ICollection is synchronized (thread safe).

ICollection.SyncRoot

获取可用于同步对 ICollection的访问的对象。Gets an object that can be used to synchronize access to the ICollection.

ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>)
ICollection<KeyValuePair<TKey,TValue>>.Clear()
ICollection<KeyValuePair<TKey,TValue>>.CopyTo(KeyValuePair<TKey,TValue>[], Int32)
ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly
ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>)
IDictionary.Add(Object, Object)

将具有所提供键和值的元素添加到不可变字典对象。Adds an element with the provided key and value to the immutable dictionary object.

IDictionary.Clear()

清除此实例。Clears this instance.

IDictionary.Contains(Object)

确定不可变字典对象是否包含具有指定键的元素。Determines whether the immutable dictionary object contains an element with the specified key.

IDictionary.GetEnumerator()

返回不可变字典对象的 IDictionaryEnumerator 对象。Returns an IDictionaryEnumerator object for the immutable dictionary object.

IDictionary.IsFixedSize

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

IDictionary.IsReadOnly

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

IDictionary.Item[Object]

获取或设置具有指定键的元素。Gets or sets the element with the specified key.

IDictionary.Keys

获取包含 ICollection<T> 的键的 IDictionary<TKey,TValue>Gets an ICollection<T> containing the keys of the IDictionary<TKey,TValue>.

IDictionary.Remove(Object)

从不可变字典对象中移除具有指定键的元素。Removes the element with the specified key from the immutable dictionary object.

IDictionary.Values

获取一个 ICollection<T>,它包含 IDictionary<TKey,TValue> 中的值。Gets an ICollection<T> containing the values in the IDictionary<TKey,TValue>.

IDictionary<TKey,TValue>.Add(TKey, TValue)
IDictionary<TKey,TValue>.Item[TKey]
IDictionary<TKey,TValue>.Keys
IDictionary<TKey,TValue>.Remove(TKey)
IDictionary<TKey,TValue>.Values
IEnumerable.GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator()
IImmutableDictionary<TKey,TValue>.Add(TKey, TValue)
IImmutableDictionary<TKey,TValue>.AddRange(IEnumerable<KeyValuePair<TKey,TValue>>)
IImmutableDictionary<TKey,TValue>.Clear()
IImmutableDictionary<TKey,TValue>.Remove(TKey)
IImmutableDictionary<TKey,TValue>.RemoveRange(IEnumerable<TKey>)
IImmutableDictionary<TKey,TValue>.SetItem(TKey, TValue)
IImmutableDictionary<TKey,TValue>.SetItems(IEnumerable<KeyValuePair<TKey,TValue>>)

扩展方法

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)

Tries to get the value associated with the specified key in the dictionary.

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue)

Tries to get the value associated with the specified key in the dictionary.

Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)

Tries to remove the value with the specified key from the dictionary.

TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)

Tries to add the specified key and value to the dictionary.

Contains<TKey,TValue>(IImmutableDictionary<TKey,TValue>, TKey, TValue)

确定指定的不可变字典是否包含指定的键/值对。Determines whether the specified immutable dictionary contains the specified key/value pair.

GetValueOrDefault<TKey,TValue>(IImmutableDictionary<TKey,TValue>, TKey)

如果字典中存在匹配的键,则获取给定键的值。Gets the value for a given key if a matching key exists in the dictionary.

GetValueOrDefault<TKey,TValue>(IImmutableDictionary<TKey,TValue>, TKey, TValue)

如果字典中存在匹配的键,则获取给定键的值。Gets the value for a given key if a matching key exists in the dictionary.

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.