> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/reactor/api-reference/ks.reactor/ks.reactor.ksatomiclist-1.md).

# Class ksAtomicList\<T>

Namespace: [KS.Reactor](/reactor/api-reference/ks.reactor.md)\
Assembly: KSCommon.dll

Wraps a list to make all read/write operations thread safe.

```csharp
public class ksAtomicList<T>
```

#### Type Parameters

`T`

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ← [ksAtomicList\<T>](/reactor/api-reference/ks.reactor/ks.reactor.ksatomiclist-1.md)

#### Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object\)), [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object-system-object\)), [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode), [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype), [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone), [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals), [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Properties

### Count <a href="#ks_reactor_ksatomiclist_1_count" id="ks_reactor_ksatomiclist_1_count"></a>

Number of values in the list.

```csharp
public int Count { get; }
```

#### Property Value

[int](https://learn.microsoft.com/dotnet/api/system.int32)

### this\[int] <a href="#ks_reactor_ksatomiclist_1_item_system_int32" id="ks_reactor_ksatomiclist_1_item_system_int32"></a>

Gets/Sets the value at an index.

```csharp
public T this[int index] { get; set; }
```

#### Property Value

T

## Methods

### Add(T) <a href="#ks_reactor_ksatomiclist_1_add__0" id="ks_reactor_ksatomiclist_1_add__0"></a>

Adds a value to the end of the list.

```csharp
public void Add(T value)
```

#### Parameters

`value` T

Value to add.

### Clear() <a href="#ks_reactor_ksatomiclist_1_clear" id="ks_reactor_ksatomiclist_1_clear"></a>

Clears the list.

```csharp
public void Clear()
```

### ForEach(ForEachCallback) <a href="#ks_reactor_ksatomiclist_1_foreach_ks_reactor_ksatomiclist__0__foreachcallback" id="ks_reactor_ksatomiclist_1_foreach_ks_reactor_ksatomiclist__0__foreachcallback"></a>

Iterates the list invoking the callback for each element. If any callback returns false, then iteration stops. A read lock is placed on the list while iteration is taking place.

```csharp
public bool ForEach(ksAtomicList<T>.ForEachCallback callback)
```

#### Parameters

`callback` [ksAtomicList](/reactor/api-reference/ks.reactor/ks.reactor.ksatomiclist-1.md)\<T>.[ForEachCallback](/reactor/api-reference/ks.reactor/ks.reactor.ksatomiclist-1/ks.reactor.ksatomiclist-1.foreachcallback.md)

Callback to invoke for each list element.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

True if all callbacks were invoked and returned true.

### Get(int, T) <a href="#ks_reactor_ksatomiclist_1_get_system_int32__0" id="ks_reactor_ksatomiclist_1_get_system_int32__0"></a>

Gets the value at an index.

```csharp
public T Get(int index, T defaultValue = default)
```

#### Parameters

`index` [int](https://learn.microsoft.com/dotnet/api/system.int32)

Index to get value at.

`defaultValue` T

Default value to return if the index is outside the bounds of the list.

#### Returns

T

Value at the given index.

### Iterate() <a href="#ks_reactor_ksatomiclist_1_iterate" id="ks_reactor_ksatomiclist_1_iterate"></a>

Returns an iterator that can be used to safely iterate the list while other threads are iterating and/or modifying the list.

Example usage:

AtomicIterator \<T> iter = list.Iterate(); while (iter.Next()) { T value = iter.Value; ... do stuff }

```csharp
public ksAtomicList<T>.Iterator Iterate()
```

#### Returns

[ksAtomicList](/reactor/api-reference/ks.reactor/ks.reactor.ksatomiclist-1.md)\<T>.[Iterator](/reactor/api-reference/ks.reactor/ks.reactor.ksatomiclist-1/ks.reactor.ksatomiclist-1.iterator.md)

Iterator.

### Remove(T) <a href="#ks_reactor_ksatomiclist_1_remove__0" id="ks_reactor_ksatomiclist_1_remove__0"></a>

Removes a value from the list.

```csharp
public bool Remove(T value)
```

#### Parameters

`value` T

Value to remove.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

True if the value was found and removed.

### RemoveAll(Predicate\<T>) <a href="#ks_reactor_ksatomiclist_1_removeall_system_predicate__0" id="ks_reactor_ksatomiclist_1_removeall_system_predicate__0"></a>

Removes all values that match a predicate.

```csharp
public int RemoveAll(Predicate<T> match)
```

#### Parameters

`match` [Predicate](https://learn.microsoft.com/dotnet/api/system.predicate-1)\<T>

Returns true to remove the value.

#### Returns

[int](https://learn.microsoft.com/dotnet/api/system.int32)

The number of values removed.

### RemoveAt(int) <a href="#ks_reactor_ksatomiclist_1_removeat_system_int32" id="ks_reactor_ksatomiclist_1_removeat_system_int32"></a>

Removes the value at an index.

```csharp
public void RemoveAt(int index)
```

#### Parameters

`index` [int](https://learn.microsoft.com/dotnet/api/system.int32)

Index to remove value at.

### RemoveRange(int, int) <a href="#ks_reactor_ksatomiclist_1_removerange_system_int32_system_int32" id="ks_reactor_ksatomiclist_1_removerange_system_int32_system_int32"></a>

Removes a range of values from the list.

```csharp
public void RemoveRange(int index, int count)
```

#### Parameters

`index` [int](https://learn.microsoft.com/dotnet/api/system.int32)

Index to remove from.

`count` [int](https://learn.microsoft.com/dotnet/api/system.int32)

Number of values to remove.

### Set(int, T) <a href="#ks_reactor_ksatomiclist_1_set_system_int32__0" id="ks_reactor_ksatomiclist_1_set_system_int32__0"></a>

Sets the value at an index, if that index is within the bounds of the list.

```csharp
public bool Set(int index, T value)
```

#### Parameters

`index` [int](https://learn.microsoft.com/dotnet/api/system.int32)

Index to set value at.

`value` T

Value to set.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

True if the index was within the bounds of the list.

### ToArray() <a href="#ks_reactor_ksatomiclist_1_toarray" id="ks_reactor_ksatomiclist_1_toarray"></a>

Returns an array that contains all elements in the list.

```csharp
public T[] ToArray()
```

#### Returns

T\[]

Array that contains all elements in the list.
