ReadOnlyDictionary<TKey,TValue> 类
定义
表示键/值对的只读泛型集合。Represents a read-only, generic collection of key/value pairs.
generic <typename TKey, typename TValue>
public ref class ReadOnlyDictionary : 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.Serializable]
public class ReadOnlyDictionary<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
type ReadOnlyDictionary<'Key, 'Value> = class
interface IDictionary<'Key, 'Value>
interface IDictionary
interface IReadOnlyDictionary<'Key, 'Value>
interface ICollection<KeyValuePair<'Key, 'Value>>
interface seq<KeyValuePair<'Key, 'Value>>
interface IEnumerable
interface ICollection
interface IReadOnlyCollection<KeyValuePair<'Key, 'Value>>
Public Class ReadOnlyDictionary(Of TKey, TValue)
Implements ICollection(Of KeyValuePair(Of TKey, TValue)), IDictionary, IDictionary(Of TKey, TValue), IEnumerable(Of KeyValuePair(Of TKey, TValue)), IReadOnlyCollection(Of KeyValuePair(Of TKey, TValue)), IReadOnlyDictionary(Of TKey, TValue)
类型参数
- TKey
字典中键的类型。The type of keys in the dictionary.
- TValue
字典中值的类型。The type of values in the dictionary.
- 继承
-
ReadOnlyDictionary<TKey,TValue>
- 属性
- 实现
-
ICollection<KeyValuePair<TKey,TValue>> IDictionary<TKey,TValue> IEnumerable<KeyValuePair<TKey,TValue>> IEnumerable<T> IReadOnlyCollection<KeyValuePair<TKey,TValue>> IReadOnlyDictionary<TKey,TValue> ICollection IDictionary IEnumerable
构造函数
ReadOnlyDictionary<TKey,TValue>(IDictionary<TKey,TValue>) |
初始化 ReadOnlyDictionary<TKey,TValue> 类的新实例,该实例是指定字典周围的包装。Initializes a new instance of the ReadOnlyDictionary<TKey,TValue> class that is a wrapper around the specified dictionary. |
属性
Count |
获取字典中项的数目。Gets the number of items in the dictionary. |
Dictionary |
获取由 ReadOnlyDictionary<TKey,TValue> 对象包装的字典。Gets the dictionary that is wrapped by this ReadOnlyDictionary<TKey,TValue> object. |
Item[TKey] |
获取具有指定键的元素。Gets the element that has the specified key. |
Keys |
获取包含字典中的键的键集合。Gets a key collection that contains the keys of the dictionary. |
Values |
获取包含词典中的值的集合。Gets a collection that contains the values in the dictionary. |
方法
ContainsKey(TKey) |
确定字典是否包含具有指定键的元素。Determines whether the dictionary contains an element that has the specified key. |
Equals(Object) |
确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
GetEnumerator() |
返回循环访问 ReadOnlyDictionary<TKey,TValue> 的枚举数。Returns an enumerator that iterates through the ReadOnlyDictionary<TKey,TValue>. |
GetHashCode() |
用作默认哈希函数。Serves as the default hash function. (继承自 Object) |
GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
ToString() |
返回一个表示当前对象的 string。Returns a string that represents the current object. (继承自 Object) |
TryGetValue(TKey, TValue) |
检索与指定键关联的值。Retrieves the value that is associated with the specified key. |
显式界面实现
ICollection.CopyTo(Array, Int32) |
从指定的数组索引开始,将字典中的元素复制到一个数组中。Copies the elements of the dictionary to an array, starting at the specified array index. |
ICollection.IsSynchronized |
获取一个值,该值指示对字典的访问是否同步(线程安全)。Gets a value that indicates whether access to the dictionary is synchronized (thread safe). |
ICollection.SyncRoot |
获取可用于同步对字典的访问的对象。Gets an object that can be used to synchronize access to the dictionary. |
ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>) |
任何情况下均引发 NotSupportedException 异常。Throws a NotSupportedException exception in all cases. |
ICollection<KeyValuePair<TKey,TValue>>.Clear() |
任何情况下均引发 NotSupportedException 异常。Throws a NotSupportedException exception in all cases. |
ICollection<KeyValuePair<TKey,TValue>>.Contains(KeyValuePair<TKey,TValue>) |
确定字典是否包含特定值。Determines whether the dictionary contains a specific value. |
ICollection<KeyValuePair<TKey,TValue>>.CopyTo(KeyValuePair<TKey,TValue>[], Int32) |
从指定的数组索引开始,将字典中的元素复制到一个数组中。Copies the elements of the dictionary to an array, starting at the specified array index. |
ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly |
获取一个值,该值指示字典是否为只读。Gets a value that indicates whether the dictionary is read-only. |
ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>) |
任何情况下均引发 NotSupportedException 异常。Throws a NotSupportedException exception in all cases. |
IDictionary.Add(Object, Object) |
任何情况下均引发 NotSupportedException 异常。Throws a NotSupportedException exception in all cases. |
IDictionary.Clear() |
任何情况下均引发 NotSupportedException 异常。Throws a NotSupportedException exception in all cases. |
IDictionary.Contains(Object) |
确定字典是否包含具有指定键的元素。Determines whether the dictionary contains an element that has the specified key. |
IDictionary.GetEnumerator() |
返回字典的一个枚举数。Returns an enumerator for the dictionary. |
IDictionary.IsFixedSize |
获取一个值,该值指示字典是否具有固定大小。Gets a value that indicates whether the dictionary has a fixed size. |
IDictionary.IsReadOnly |
获取一个值,该值指示字典是否为只读。Gets a value that indicates whether the dictionary is read-only. |
IDictionary.Item[Object] |
获取具有指定键的元素。Gets the element that has the specified key. |
IDictionary.Keys |
获取包含词典中的键的集合。Gets a collection that contains the keys of the dictionary. |
IDictionary.Remove(Object) |
任何情况下均引发 NotSupportedException 异常。Throws a NotSupportedException exception in all cases. |
IDictionary.Values |
获取包含词典中的值的集合。Gets a collection that contains the values in the dictionary. |
IDictionary<TKey,TValue>.Add(TKey, TValue) |
任何情况下均引发 NotSupportedException 异常。Throws a NotSupportedException exception in all cases. |
IDictionary<TKey,TValue>.Item[TKey] |
获取具有指定键的元素。Gets the element that has the specified key. |
IDictionary<TKey,TValue>.Keys |
获取包含词典中的键的集合。Gets a collection that contains the keys of the dictionary. |
IDictionary<TKey,TValue>.Remove(TKey) |
任何情况下均引发 NotSupportedException 异常。Throws a NotSupportedException exception in all cases. |
IDictionary<TKey,TValue>.Values |
获取包含词典中的值的集合。Gets a collection that contains the values in the dictionary. |
IEnumerable.GetEnumerator() |
返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection. |
IReadOnlyDictionary<TKey,TValue>.Keys |
获取包含只读字典中的密钥的可枚举集合。Gets an enumerable collection that contains the keys in the read-only dictionary. |
IReadOnlyDictionary<TKey,TValue>.Values |
获取包含只读字典中的值的可枚举集合。Gets an enumerable collection that contains the values in the read-only dictionary. |
扩展方法
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) |
尝试获取与 |
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) |
尝试获取 |
Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) |
尝试从 |
TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) |
尝试将指定的 |
CopyToDataTable<T>(IEnumerable<T>) |
在给定其泛型参数 |
CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) |
在给定其泛型参数 |
CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) |
在给定其泛型参数 |
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 转换为 IQueryable。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. 集合中仅包括具有匹配 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. |