IReadOnlyDictionary<TKey,TValue>.TryGetValue(TKey, TValue) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Feedback
https://aka.ms/ContentUserFeedback.
Binnenkort: Gedurende 2024 worden GitHub Issues uitgefaseerd als het feedbackmechanisme voor inhoud. Dit wordt vervangen door een nieuw feedbacksysteem. Ga voor meer informatie naar:Feedback verzenden en bekijken voor