Skip to content

M_CodeJam_Collections_DictionaryExtensions_AddOrUpdate__2

Andrew Koryavchenko edited this page Jun 17, 2018 · 10 revisions

DictionaryExtensions.AddOrUpdate(TKey, TValue) Method (ConcurrentDictionary(TKey, TValue), TKey, Func(TKey, TValue))

Adds a key/value pair to the ConcurrentDictionary(TKey, TValue) if the key does not already exist, or updates a key/value pair ConcurrentDictionary(TKey, TValue) by using the specified function if the key already exists.

Namespace: CodeJam.Collections
Assembly: CodeJam (in CodeJam.dll) Version: 2.1.0.0

Syntax

C#

public static TValue AddOrUpdate<TKey, TValue>(
	this ConcurrentDictionary<TKey, TValue> dictionary,
	TKey key,
	Func<TKey, TValue> valueFactory
)

VB

<ExtensionAttribute>
Public Shared Function AddOrUpdate(Of TKey, TValue) ( 
	dictionary As ConcurrentDictionary(Of TKey, TValue),
	key As TKey,
	valueFactory As Func(Of TKey, TValue)
) As TValue

F#

[<ExtensionAttribute>]
static member AddOrUpdate : 
        dictionary : ConcurrentDictionary<'TKey, 'TValue> * 
        key : 'TKey * 
        valueFactory : Func<'TKey, 'TValue> -> 'TValue 

Parameters

 

dictionary
Type: System.Collections.Concurrent.ConcurrentDictionary(TKey, TValue)
The dictionary.
key
Type: TKey
The key to be added or whose value should be updated
valueFactory
Type: System.Func(TKey, TValue)
The function used to generate a value.

Type Parameters

 

TKey
[Missing documentation for "M:CodeJam.Collections.DictionaryExtensions.AddOrUpdate2(System.Collections.Concurrent.ConcurrentDictionary{0,1},0,System.Func{0,1})"]
TValue
[Missing documentation for "M:CodeJam.Collections.DictionaryExtensions.AddOrUpdate2(System.Collections.Concurrent.ConcurrentDictionary{0,1},0,System.Func{0,1})"]

Return Value

Type: TValue
The new value for the key.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type ConcurrentDictionary(TKey, TValue). When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

See Also

Reference

DictionaryExtensions Class
AddOrUpdate Overload
CodeJam.Collections Namespace

Clone this wiki locally