IReadOnlyDictionary<TKey,TValue>.Item[TKey] 属性

定义

获取在只读目录中有指定键的元素。Gets the element that has the specified key in the read-only dictionary.

public:
 property TValue default[TKey] { TValue get(TKey key); };
public TValue this[TKey key] { get; }
member this.Item('Key) : 'Value
Default Public ReadOnly Property Item(key As TKey) As TValue

参数

key
TKey

要定位的键。The key to locate.

属性值

TValue

在只读目录中有指定键的元素。The element that has the specified key in the read-only dictionary.

例外

keynullkey is null.

检索了属性但没有找到 keyThe property is retrieved and key is not found.

注解

利用此属性,您能够通过使用以下语法来访问集合中的特定元素:myCollection[key](在 Visual Basic 中为 myCollection(key))。This property lets you access a specific element in the collection by using the following syntax: myCollection[key] (myCollection(key) in Visual Basic).

各个实现确定对象的相等性的方式可能会有所不同。例如,实现 IReadOnlyDictionary<TKey,TValue> 的类可能使用 Comparer<T>.Default 属性,也可能实现 IComparer<T> 方法。Implementations can vary in how they determine the equality of objects: for example, the class that implements IReadOnlyDictionary<TKey,TValue> might use the Comparer<T>.Default property, or it might implement the IComparer<T> method.

实现在是否允许时可能有所不同 key nullImplementations can vary in whether they allow key to be null.

适用于