Wintellect.PowerCollections Namespace
Algorithms Class
GhostDoc Pro Sample Help File

OrderedDictionary<(Of <(<'TKey, TValue>)>)>..::..GetValueElseAdd Method

Finds a key in the dictionary. If the dictionary already contains a key equal to the passed key, then the existing value is returned via value. If the dictionary doesn't contain that key, then value is associated with that key.

Namespace:  Wintellect.PowerCollections
Assembly:  PowerCollections (in PowerCollections.dll)

Syntax


public bool GetValueElseAdd(
	TKey key,
	ref TValue value
)
Public Function GetValueElseAdd ( _
	key As TKey, _
	ByRef value As TValue _
) As Boolean
public:
bool^ GetValueElseAdd(
	TKey key, 
	TValue% value
)

Parameters

key
Type: TKey
The new key.
value
Type: TValue%
The new value to associated with that key, if the key isn't present. If the key was present, returns the exist value associated with that key.

Return Value

True if key was already present, false if key wasn't present (and a new value was added).

Remarks


between keys is determined by the comparison instance or delegate used to create the dictionary.

This method takes time O(log N), where N is the number of keys in the dictionary. If a value is added, It is more efficient than calling TryGetValue followed by Add, because the dictionary is not searched twice.