Skip to content

M_CodeJam_Collections_DictionaryExtensions_GetOrAdd__2_2

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

DictionaryExtensions.GetOrAdd(TKey, TValue) Method (IDictionary(TKey, TValue), 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: 2.1.0.0

Syntax

C#

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

VB

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

F#

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

Parameters

 

dictionary
Type: System.Collections.Generic.IDictionary(TKey, TValue)
The dictionary.
key
Type: TKey
The key of the element to add.
value
Type: TValue
the value to be added, if the key does not already exist

Type Parameters

 

TKey
[Missing documentation for "M:CodeJam.Collections.DictionaryExtensions.GetOrAdd2(System.Collections.Generic.IDictionary{0,1},0,1)"\]</dd><dt>TValue</dt><dd>\[Missing <typeparam name="TValue"/> documentation for "M:CodeJam.Collections.DictionaryExtensions.GetOrAdd2(System.Collections.Generic.IDictionary{0,1},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