# NativeSlice<T>

> Provides a view on a buffer of native memory most commonly acquired from a NativeArray<T>.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Collections](/engine/6000.7/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.ManagedKernelModule
* **Implements:** [IEnumerable\<T>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable), [IEquatable\<NativeSlice\<T>>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct NativeSlice<T> : IEnumerable<T>, IEnumerable, IEquatable<NativeSlice<T>> where T : struct
```

## Remarks

A `NativeSlice` includes safety mechanisms for use with the job system. A `NativeSlice` doesn't own any memory allocations and can't be disposed, unlike a `NativeArray`[NativeArray\<T>](/engine/6000.7/script-reference/unity/collections/nativearray1.md).

A `NativeSlice` supports a stride value and doesn't necessarily represent a contiguous memory range. The stride value determines the number of bytes from the first byte of the element to the first byte of the next element. The stride value must always be a multiple of the size of the type of the slice in bytes. The stride value allows you to skip elements from the underlying buffer.

By default, the stride is set to the size of the type of slice in bytes. This means that the slice represents a contiguous memory range. If you don't need a stride and are only working with contiguous memory ranges, use [NativeArray\<T>](/engine/6000.7/script-reference/unity/collections/nativearray1.md) instead.

## Constructors

| Constructor                                                                                                                                                                                 | Description                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| [NativeSlice\`1(Unity.Collections.NativeArray\{\`0})](/engine/6000.7/script-reference/unity/collections/nativeslice1/ctor.md#nativeslice\(nativearrayt\))                                   | Constructs a new NativeSlice from a NativeArray.                                                               |
| [NativeSlice\`1(Unity.Collections.NativeArray\{\`0},System.Int32)](/engine/6000.7/script-reference/unity/collections/nativeslice1/ctor.md#nativeslice\(nativearrayt-int\))                  | Constructs a new NativeSlice from a NativeArray, with a defined start index.                                   |
| [NativeSlice\`1(Unity.Collections.NativeArray\{\`0},System.Int32,System.Int32)](/engine/6000.7/script-reference/unity/collections/nativeslice1/ctor.md#nativeslice\(nativearrayt-int-int\)) | Constructs a new NativeSlice of defined length `length`, from a NativeArray with a defined start index.        |
| [NativeSlice\`1(Unity.Collections.NativeSlice\{\`0},System.Int32)](/engine/6000.7/script-reference/unity/collections/nativeslice1/ctor.md#nativeslice\(nativeslicet-int\))                  | Constructs a new NativeSlice from another NativeSlice, with a defined start index.                             |
| [NativeSlice\`1(Unity.Collections.NativeSlice\{\`0},System.Int32,System.Int32)](/engine/6000.7/script-reference/unity/collections/nativeslice1/ctor.md#nativeslice\(nativeslicet-int-int\)) | Constructs a new NativeSlice of defined length `length`, from another NativeSlice, with a defined start index. |

## Properties

| Property                                                                           | Description                                                                                                                  |
| ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| [this\[\]](/engine/6000.7/script-reference/unity/collections/nativeslice1/item.md) | Accesses [NativeSlice\<T>](/engine/6000.7/script-reference/unity/collections/nativeslice1.md) elements by index.             |
| [Length](/engine/6000.7/script-reference/unity/collections/nativeslice1/length.md) | Represents the number of elements in a [NativeSlice\<T>](/engine/6000.7/script-reference/unity/collections/nativeslice1.md). |
| [Stride](/engine/6000.7/script-reference/unity/collections/nativeslice1/stride.md) | Gets the stride value for the [NativeSlice\<T>](/engine/6000.7/script-reference/unity/collections/nativeslice1.md) instance. |

## Methods

| Method                                                                                               | Description                                                                                                                                                                                                                                      |
| ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [CopyFrom](/engine/6000.7/script-reference/unity/collections/nativeslice1/copyfrom.md)               | Copies all the elements from a [NativeSlice\<T>](/engine/6000.7/script-reference/unity/collections/nativeslice1.md) or managed array of the same length.                                                                                         |
| [CopyTo](/engine/6000.7/script-reference/unity/collections/nativeslice1/copyto.md)                   | Copies all the elements of a [NativeSlice\<T>](/engine/6000.7/script-reference/unity/collections/nativeslice1.md) to a [NativeArray\<T>](/engine/6000.7/script-reference/unity/collections/nativearray1.md) or managed array of the same length. |
| [GetEnumerator](/engine/6000.7/script-reference/unity/collections/nativeslice1/getenumerator.md)     | Gets an enumerator to iterate through the elements of a [NativeSlice\<T>](/engine/6000.7/script-reference/unity/collections/nativeslice1.md).                                                                                                    |
| [SliceConvert](/engine/6000.7/script-reference/unity/collections/nativeslice1/sliceconvert.md)       | Reinterprets a NativeSlice with a different data type (type punning).                                                                                                                                                                            |
| [SliceWithStride](/engine/6000.7/script-reference/unity/collections/nativeslice1/slicewithstride.md) | SliceWithStride.                                                                                                                                                                                                                                 |
| [ToArray](/engine/6000.7/script-reference/unity/collections/nativeslice1/toarray.md)                 | Converts a [NativeSlice\<T>](/engine/6000.7/script-reference/unity/collections/nativeslice1.md) to managed array.                                                                                                                                |
