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

ConditionalWeakTable<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 of the specified key.

Namespace:  System.Runtime.CompilerServices
Assembly:  mscorlib (in mscorlib.dll)

public bool TryGetValue(
	TKey key,
	out TValue value
)

Parameters

key
Type: TKey
The key that represents an object with an attached property.
value
Type: TValue %
When this method returns, contains the attached property value. If key is not found, value contains the default value.

Return Value

Type: System.Boolean
true if key is found; otherwise, false.

ExceptionCondition
ArgumentNullException

key is null.

If the key is garbage-collected during this operation, the method may return false and set value to the default value (as if the key were not present).

The following example defines a MainClass class and a MainInfo class, which provides information about the MainClass instance. The example calls the Add, GetOrCreateValue, and GetValue methods to add key/value pairs to a ConditionalWeakTable<TKey, TValue> table. In each case, the example calls the TryGetValue method to confirm that the key/value pair has been added to the table.

Windows Phone OS

Supported in: 8.1, 8.0

  • SecurityCriticalAttribute 

    requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Show:
© 2017 Microsoft