DictionaryHelper.TryAdd<TKey, TValue> Method

Safely adds a new item to the Dictionary object as necessary. There is an option to replace the value if the key already exists. Otherwise, if the key already exists, no errors are thrown.
<Extension()> _ 
Public Shared Function TryAdd(Of _ 
TKey, _ 
TValue)( _ 
ByVal source As IDictionary(Of TKey, TValue), _ 
ByVal key As TKey, _ 
ByVal value As TValue, _ 
Optional ByVal overwrite_value As Boolean = false, _ 
Optional ByVal error_logger As Action(Of TKey, TValue) = null _ 
) As Boolean
This language is not supported or no code example is available.
public static bool TryAdd<TKey, TValue>( 
this IDictionary<TKey, TValue> source
TKey key
TValue value
bool overwrite_value = false, 
Action<TKey, TValue> error_logger = null 
)
This language is not supported or no code example is available.
[Extension()] 
generic<typename TKey, typename TValue> 
public:  
static bool TryAdd( 
IDictionary<TKey, TValue>^ source
TKey^ key
TValue^ value
bool overwrite_value
Action<TKey, TValue>^ error_logger 
)
This language is not supported or no code example is available.
JScript does not support generic types and methods.
This language is not supported or no code example is available.

Type Parameters

TKey

TValue

Parameters

source
IDictionary<TKey, TValue>

<default>

key
TKey

<default>

value
TValue

<default>

overwrite_value
bool

<default>

error_logger
Action<TKey, TValue>

<default>

Return Value

bool

.NET Framework

Supported in: 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1

In this article

Definition