ConcurrentDictionary<TKey, TValue>::TryUpdate Method (TKey, TValue, TValue)

.NET Framework (current version)

Compares the existing value for the specified key with a specified value, and if they are equal, updates the key with a third value.

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

bool TryUpdate(
	TKey key,
	TValue newValue,
	TValue comparisonValue


Type: TKey

The key whose value is compared with comparisonValue and possibly replaced.

Type: TValue

The value that replaces the value of the element that has the specified key if the comparison results in equality.

Type: TValue

The value that is compared to the value of the element that has the specified key.

Return Value

Type: System::Boolean

true if the value with key was equal to comparisonValue and was replaced with newValue; otherwise, false.

Exception Condition

key is null.

The following example shows how to call the TryUpdate method:

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

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