    

 ## On this page

  

 

 # Class UniqueItemList&lt;T\\&gt;

 Last update: 09.03.2026 

Namespace: [OpenTD.Utility](OpenTD.Utility.md)  
Assembly: OpenTD.dll

Acts like a List, except Add and Insert will remove existing items that equal the added/inserted item (according to its definition of Equals)

```csharp
[MessagePackObject(true)]
public class UniqueItemList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable

```

#### Type Parameters

`T`

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ← [UniqueItemList&lt;T&gt;](OpenTD.Utility.UniqueItemList-1.md)

## Implements

[IList&lt;T&gt;](https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1), [ICollection&lt;T&gt;](https://learn.microsoft.com/dotnet/api/system.collections.generic.icollection-1), [IEnumerable&lt;T&gt;](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable)

## 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

Gets the number of elements contained in the .

```csharp
public int Count { get; }

```

#### Property Value

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

### IsReadOnly

Gets a value indicating whether the  is read-only.

```csharp
public bool IsReadOnly { get; }

```

#### Property Value

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

### this\[int\]

Gets or sets the element at the specified index.

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

```

#### Property Value

T

#### Exceptions

[ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception)

`index` is not a valid index in the .

[NotSupportedException](https://learn.microsoft.com/dotnet/api/system.notsupportedexception)

The property is set and the  is read-only.

## Methods

### Add(T)

Will remove any existing item that equals the added item.

```csharp
public void Add(T item)

```

#### Parameters

`item` T

### Clear()

Removes all items from the .

```csharp
public void Clear()

```

#### Exceptions

[NotSupportedException](https://learn.microsoft.com/dotnet/api/system.notsupportedexception)

The  is read-only.

### Contains(T)

Determines whether the  contains a specific value.

```csharp
public bool Contains(T item)

```

#### Parameters

`item` T

The object to locate in the .

#### Returns

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

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if `item` is found in the ; otherwise, [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

### CopyTo(T\[\], int)

Copies the elements of the  to an , starting at a particular  index.

```csharp
public void CopyTo(T[] array, int arrayIndex)

```

#### Parameters

`array` T\[\]

The one-dimensional  that is the destination of the elements copied from . The  must have zero-based indexing.

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

The zero-based index in `array` at which copying begins.

#### Exceptions

[ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`array` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

[ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception)

`arrayIndex` is less than 0.

[ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

The number of elements in the source  is greater than the available space from `arrayIndex` to the end of the destination `array`.

### GetEnumerator()

Returns an enumerator that iterates through the collection.

```csharp
public IEnumerator<T> GetEnumerator()

```

#### Returns

[IEnumerator](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerator-1)&lt;T&gt;

An enumerator that can be used to iterate through the collection.

### IndexOf(T)

Determines the index of a specific item in the .

```csharp
public int IndexOf(T item)

```

#### Parameters

`item` T

The object to locate in the .

#### Returns

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

The index of `item` if found in the list; otherwise, -1.

### Insert(int, T)

Will remove any existing item that equals the inserted item.

```csharp
public void Insert(int index, T item)

```

#### Parameters

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

`item` T

### Remove(T)

Removes the first occurrence of a specific object from the .

```csharp
public bool Remove(T item)

```

#### Parameters

`item` T

The object to remove from the .

#### Returns

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

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if `item` was successfully removed from the ; otherwise, [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool). This method also returns [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if `item` is not found in the original .

#### Exceptions

[NotSupportedException](https://learn.microsoft.com/dotnet/api/system.notsupportedexception)

The  is read-only.

### RemoveAll(Predicate&lt;T&gt;)

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

```

#### Parameters

`match` [Predicate](https://learn.microsoft.com/dotnet/api/system.predicate-1)&lt;T&gt;

#### Returns

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

### RemoveAt(int)

Removes the  item at the specified index.

```csharp
public void RemoveAt(int index)

```

#### Parameters

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

The zero-based index of the item to remove.

#### Exceptions

[ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception)

`index` is not a valid index in the .

[NotSupportedException](https://learn.microsoft.com/dotnet/api/system.notsupportedexception)

The  is read-only.