ConditionalWeakTable<TKey, TValue>::TryGetValue Method (TKey, TValue%)

 

Gets the value of the specified key.

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

public:
bool TryGetValue(
	TKey key,
	[OutAttribute] 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.

Exception Condition
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.

No code example is currently available or this language may not be supported.

SecurityCriticalAttribute

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show: