CollectionsMarshal.GetValueRefOrAddDefault<TKey,TValue> Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for