Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

OrderedDictionary<TKey,TValue>.TryAdd Method

Definition

Namespace:
System.Collections.Generic
Assembly:
System.Collections.dll

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.

Overloads

Name Description
TryAdd(TKey, TValue, Int32)

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

TryAdd(TKey, TValue)

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

TryAdd(TKey, TValue, Int32)

Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs

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

public:
 bool TryAdd(TKey key, TValue value, [Runtime::InteropServices::Out] int % index);
public bool TryAdd(TKey key, TValue value, out int index);
member this.TryAdd : 'Key * 'Value * int -> bool
Public Function TryAdd (key As TKey, value As TValue, ByRef index As Integer) As Boolean

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.

index
Int32

The index of the added or existing key. This is always a valid index into the dictionary.

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

TryAdd(TKey, TValue)

Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs

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

public:
 bool TryAdd(TKey key, TValue value);
public bool TryAdd(TKey key, TValue value);
member this.TryAdd : 'Key * 'Value -> bool
Public Function TryAdd (key As TKey, value As TValue) As Boolean

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


Feedback

Was this page helpful?