Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


TryAdd

Adds a new key-value pair.
Read time 1 minuteLast updated 12 days ago

Definition

  • Type: Method
  • Namespace: Unity.Collections
  • Assembly: UnityEngine.ManagedKernelModule

TryAdd(T, T)

Adds a new key-value pair.
public bool TryAdd(TKey key, TValue item)

Parameters

key

T
The key to add.

item

T
The value to add.

Returns

Type

Description

boolTrue 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.
public bool TryAdd(TKey key, TValue item, int threadIndexOverride)

Parameters

key

T
The key to add.

item

T
The value to add.

threadIndexOverride

The thread index which must be set by a field from a job struct with the NativeSetThreadIndexAttribute attribute.

Returns

Type

Description

boolTrue if the key-value pair was added.

Remarks

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