CollectionsMarshal.GetValueRefOrAddDefault<TKey,TValue> Method

Definition

Gets a reference to a TValue in the specified dictionary, adding a new entry with a default value if the key does not exist.

public:
generic <typename TKey, typename TValue>
 static TValue % GetValueRefOrAddDefault(System::Collections::Generic::Dictionary<TKey, TValue> ^ dictionary, TKey key, [Runtime::InteropServices::Out] bool % exists);
public static ref TValue? GetValueRefOrAddDefault<TKey,TValue> (System.Collections.Generic.Dictionary<TKey,TValue> dictionary, TKey key, out bool exists);
static member GetValueRefOrAddDefault : System.Collections.Generic.Dictionary<'Key, 'Value> * 'Key * bool -> 'Value
Public Shared Function GetValueRefOrAddDefault(Of TKey, TValue) (dictionary As Dictionary(Of TKey, TValue), key As TKey, ByRef exists As Boolean) As TValue

Type Parameters

TKey

The type of a key.

TValue

The type of a value.

Parameters

dictionary
Dictionary<TKey,TValue>

The dictionary to get the reference to TValue from.

key
TKey

The key used for lookup.

exists
Boolean

When this method returns, contains true if key already existed in the dictionary, and false if a new entry was added.

Returns

TValue

A reference to a TValue in the specified dictionary.

Remarks

Items should not be added to or removed from the Dictionary<TKey,TValue> while the ref TValue is in use.

Applies to