Breyta

Deila með


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

Definition

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 * 'Value -> bool
Public Function TryGetValue (key As TKey, ByRef value As TValue) As Boolean

Parameters

key
TKey

The key to locate.

value
TValue

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.

Returns

true if the object that implements the IReadOnlyDictionary<TKey,TValue> interface contains an element that has the specified key; otherwise, false.

Exceptions

key is null.

Remarks

This method combines the functionality of the ContainsKey method and the Item[] property.

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.

Applies to