TryGetValue Method
Collapse the table of content
Expand the table of content

IReadOnlyDictionary(Of TKey, TValue).TryGetValue Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets the value that is associated with the specified key.

Namespace:  System.Collections.Generic
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Function TryGetValue ( _
	key As TKey, _
	<OutAttribute> ByRef value As TValue _
) As Boolean

Parameters

key
Type: TKey
The key to locate.
value
Type: 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.

Return Value

Type: System.Boolean
true if the object that implements the IReadOnlyDictionary(Of TKey, TValue) interface contains an element that has the specified key; otherwise, false.

ExceptionCondition
ArgumentNullException

key is Nothing.

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 Nothing for reference types.

Windows Phone OS

Supported in: 8.1, 8.0

Show:
© 2017 Microsoft