# UnsafeList<T>

> An unmanaged, resizable list.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Collections.LowLevel.Unsafe](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe.md)
* **Assembly:** UnityEngine.ManagedKernelModule
* **Implements:** [INativeDisposable](/engine/6000.7/script-reference/unity/collections/inativedisposable.md), [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable), [INativeList\<T>](/engine/6000.7/script-reference/unity/collections/inativelist1.md), [IIndexable\<T>](/engine/6000.7/script-reference/unity/collections/iindexable1.md), [IEnumerable\<T>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable)

```csharp
public struct UnsafeList<T> : INativeDisposable, IDisposable, INativeList<T>, IIndexable<T>, IEnumerable<T>, IEnumerable where T : unmanaged
```

## Fields

| Value                                                                                                      | Description                                                 |
| ---------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| [Allocator](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/allocator.md)    | The allocator used to create the internal buffer.           |
| [m\_capacity](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/m-capacity.md) | The number of elements that can fit in the internal buffer. |
| [m\_length](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/m-length.md)     | The number of elements.                                     |
| [Ptr](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/ptr.md)                | The internal buffer of this list.                           |

## Static Fields

| Value                                                                                                       | Description                                                     |
| ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| [MaxCapacity](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/maxcapacity.md) | The maximum number of elements this type of container can hold. |

## Constructors

| Constructor                                                                                                                                                                                                                                                       | Description                                        |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
| [UnsafeList\`1(\`0\*,System.Int32)](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/ctor.md#unsafelist\(0*-int\))                                                                                                                   | Initializes and returns an instance of UnsafeList. |
| [UnsafeList\`1(System.Int32,Unity.Collections.AllocatorManager.AllocatorHandle,Unity.Collections.NativeArrayOptions)](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/ctor.md#unsafelist\(int-allocatorhandle-nativearrayoptions\)) | Initializes and returns an instance of UnsafeList. |

## Properties

| Property                                                                                                | Description                                                     |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| [Capacity](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/capacity.md)   | The number of elements that can fit in the internal buffer.     |
| [IsCreated](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/iscreated.md) | Whether this list has been allocated (and not yet deallocated). |
| [IsEmpty](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/isempty.md)     | Whether the list is empty.                                      |
| [this\[\]](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/item.md)       | The element at an index.                                        |
| [Length](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/length.md)       | The number of elements.                                         |

## Methods

| Method                                                                                                                              | Description                                                                                                                                         |
| ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Add](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/add.md)                                         | Adds an element to the end of the list.                                                                                                             |
| [AddNoResize](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/addnoresize.md)                         | Adds an element to the end of this list.                                                                                                            |
| [AddRange](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/addrange.md)                               | Copies elements from a ReadOnlySpan to the end of this list.                                                                                        |
| [AddRangeNoResize](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/addrangenoresize.md)               | Copies elements from a ReadOnlySpan to the end of this list.                                                                                        |
| [AddReplicate](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/addreplicate.md)                       | Appends value count times to the end of this list.                                                                                                  |
| [AsParallelReader](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/asparallelreader.md)               | **Obsolete.** Use [UnsafeList\<T>.AsReadOnly](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/asreadonly.md) instead. |
| [AsParallelWriter](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/asparallelwriter.md)               | Returns a parallel writer of this list.                                                                                                             |
| [AsReadOnly](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/asreadonly.md)                           | Returns a read only of this list.                                                                                                                   |
| [AsReadOnlySpan](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/asreadonlyspan.md)                   | Returns ReadOnlySpan\\\<T\\> view of this container.                                                                                                |
| [AsSpan](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/asspan.md)                                   | Returns Span\\\<T\\> view of this container.                                                                                                        |
| [Clear](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/clear.md)                                     | Sets the length to 0.                                                                                                                               |
| [CopyFrom](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/copyfrom.md)                               | Copies all elements of specified container to this container.                                                                                       |
| [Dispose](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/dispose.md)                                 | Releases all resources (memory).                                                                                                                    |
| [ElementAt](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/elementat.md)                             | Returns a reference to the element at a given index.                                                                                                |
| [GetEnumerator](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/getenumerator.md)                     | Returns an enumerator over the elements of the list.                                                                                                |
| [GetUnsafePtr](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/getunsafeptr.md)                       | Get a pointer to the data.                                                                                                                          |
| [GetUnsafeReadOnlyPtr](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/getunsafereadonlyptr.md)       | Get a pointer to the data.                                                                                                                          |
| [InsertRange](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/insertrange.md)                         | Shifts elements toward the end of this list, increasing its length.                                                                                 |
| [InsertRangeWithBeginEnd](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/insertrangewithbeginend.md) | Shifts elements toward the end of this list, increasing its length.                                                                                 |
| [RemoveAt](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/removeat.md)                               | Removes the element at an index, shifting everything above it down by one. Decrements the length by 1.                                              |
| [RemoveAtSwapBack](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/removeatswapback.md)               | Copies the last element of this list to the specified index. Decrements the length by 1.                                                            |
| [RemoveRange](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/removerange.md)                         | Removes "N" elements in a range, shifting everything above the range down by "N". Decrements the length by "N".                                     |
| [RemoveRangeSwapBack](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/removerangeswapback.md)         | Copies the last "N" elements of this list to a range in this list. Decrements the length by "N".                                                    |
| [Resize](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/resize.md)                                   | Sets the length, expanding the capacity if necessary.                                                                                               |
| [SetCapacity](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/setcapacity.md)                         | Sets the capacity.                                                                                                                                  |
| [TrimExcess](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/trimexcess.md)                           | Sets the capacity to match the length.                                                                                                              |

## Static Methods

| Method                                                                                              | Description         |
| --------------------------------------------------------------------------------------------------- | ------------------- |
| [Create](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/create.md)   | Returns a new list. |
| [Destroy](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/destroy.md) | Destroys the list.  |

## Structs

| Struct                                                                                                                           | Description                                                                                                                                     |
| -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| [UnsafeList\<T>.Enumerator](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/enumerator.md)         | An enumerator over the elements of a list.                                                                                                      |
| [UnsafeList\<T>.ParallelReader](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/parallelreader.md) | **Obsolete.** Use [UnsafeList\<T>.ReadOnly](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/readonly.md) instead. |
| [UnsafeList\<T>.ParallelWriter](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/parallelwriter.md) | A parallel writer for an UnsafeList\\\<T\\>.                                                                                                    |
| [UnsafeList\<T>.ReadOnly](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1/readonly.md)             | A read only for an UnsafeList\\\<T\\>.                                                                                                          |
