Skip to content

M_CodeJam_Collections_DictionaryExtensions_GetOrAdd__2_1

Andrew Koryavchenko edited this page Jul 4, 2017 · 10 revisions

DictionaryExtensions.GetOrAdd(TKey, TValue) Method (IDictionary(TKey, TValue), TKey, Func(TKey, TValue))

Adds a key/value pair to the IDictionary(TKey, TValue) if the key does not already exist.

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

Syntax

C#

public static TValue GetOrAdd<TKey, TValue>(
	this IDictionary<TKey, TValue> dictionary,
	TKey key,
	Func<TKey, TValue> valueFactory
)

VB

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

F#

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

Parameters

 

dictionary
Type: System.Collections.Generic.IDictionary(TKey, TValue)
The dictionary.
key
Type: TKey
The key of the element to add.
valueFactory
Type: System.Func(TKey, TValue)
The function used to generate a value for the key

Type Parameters

 

TKey
[Missing documentation for "M:CodeJam.Collections.DictionaryExtensions.GetOrAdd2(System.Collections.Generic.IDictionary{0,1},0,System.Func{0,1})"]
TValue
[Missing documentation for "M:CodeJam.Collections.DictionaryExtensions.GetOrAdd2(System.Collections.Generic.IDictionary{0,1},0,System.Func{0,1})"]

Return Value

Type: TValue
The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IDictionary(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
GetOrAdd Overload
CodeJam.Collections Namespace

Clone this wiki locally