IReadOnlyDictionary<TKey,TValue>.TryGetValue(TKey, TValue) IReadOnlyDictionary<TKey,TValue>.TryGetValue(TKey, TValue) IReadOnlyDictionary<TKey,TValue>.TryGetValue(TKey, TValue) IReadOnlyDictionary<TKey,TValue>.TryGetValue(TKey, TValue) Method

定義

取得與指定之索引鍵相關聯的值。Gets the value that is associated with the specified key.

public:
 bool TryGetValue(TKey key, [Runtime::InteropServices::Out] TValue % value);
public bool TryGetValue (TKey key, out TValue value);
abstract member TryGetValue : 'Key *  -> bool
Public Function TryGetValue (key As TKey, ByRef value As TValue) As Boolean

參數

key
TKey TKey TKey TKey

要尋找的索引鍵。The key to locate.

value
TValue TValue TValue TValue

這個方法傳回時,如果找到索引鍵,則為與指定索引鍵關聯的值,否則為 value 參數的型別預設值。When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. 這個參數會以未初始化的狀態傳遞。This parameter is passed uninitialized.

傳回

如果實作 IReadOnlyDictionary<TKey,TValue> 介面之物件包含具有指定之索引鍵的項目,則為 true,否則為 falsetrue if the object that implements the IReadOnlyDictionary<TKey,TValue> interface contains an element that has the specified key; otherwise, false.

例外狀況

備註

這個方法會結合的功能ContainsKey方法和Item[TKey]屬性。This method combines the functionality of the ContainsKey method and the Item[TKey] property.

如果找不到索引鍵,value參數的類型取得適當的預設值TValue: 0 (零) 的整數類型,例如false布林類型,以及null參考型別。If the key is not found, the value parameter gets the appropriate default value for the type TValue: for example, 0 (zero) for integer types, false for Boolean types, and null for reference types.

適用於