語言

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

定義

取得具有唯讀字典中指定索引鍵的專案。

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

找到的關鍵。

屬性值

TValue

在唯讀字典中擁有指定金鑰的元素。

例外狀況

key 是 null。

該屬性被檢索,但 key 找不到。

備註

這個特性讓你可以透過以下語法存取集合中的特定元素: myCollection[key] (myCollection(key) 在 Visual Basic 中)。

實作方式可能不同,例如實作 IReadOnlyDictionary<TKey,TValue> 的類別可能使用該 Comparer<T>.Default 屬性,或實作該 IComparer<T> 方法。

實作方式可能有所不同,是否允許 key 。null

適用於