# TryAdd

> Adds a new key-value pair.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Collections](/engine/6000.7/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.ManagedKernelModule

## TryAdd(T, T)

Adds a new key-value pair.

```csharp
public bool TryAdd(TKey key, TValue item)
```

### Parameters

**** (T): The key to add.**** (T): The value to add.

### Returns

| Type                                                          | Description                           |
| ------------------------------------------------------------- | ------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the key-value pair was added. |

### Remarks

If the key is already present, this method returns false without modifying this hash map.

## TryAdd(T, T, int)

Adds a new key-value pair.

```csharp
public bool TryAdd(TKey key, TValue item, int threadIndexOverride)
```

### Parameters

**** (T): The key to add.**** (T): The value to add.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The thread index which must be set by a field from a job struct with the NativeSetThreadIndexAttribute attribute.

### Returns

| Type                                                          | Description                           |
| ------------------------------------------------------------- | ------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the key-value pair was added. |

### Remarks

If the key is already present, this method returns false without modifying this hash map.
