OrderedDictionary<TKey,TValue>.TryAdd Method

Definition

Overloads

TryAdd(TKey, TValue, Int32)
TryAdd(TKey, TValue)

Adds the specified key and value to the dictionary if the key doesn't already exist.

TryAdd(TKey, TValue, Int32)

C#
public bool TryAdd(TKey key, TValue value, out int index);

Parameters

key
TKey
value
TValue
index
Int32

Returns

Applies to

.NET 10
Produk Versi
.NET 10

TryAdd(TKey, TValue)

Adds the specified key and value to the dictionary if the key doesn't already exist.

C#
public bool TryAdd(TKey key, TValue value);

Parameters

key
TKey

The key of the element to add.

value
TValue

The value of the element to add. The value can be null for reference types.

Returns

true if the key didn't exist and the key and value were added to the dictionary; otherwise, false.

Exceptions

key is null.

Applies to

.NET 10 dan .NET 9
Produk Versi
.NET 9, 10