# IndexOf

> Finds the index of the first occurrence of a particular value in this container.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Collections](/engine/6000.7/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.ManagedKernelModule

## IndexOf\<T, U>(NativeArray\<T>, T)

Finds the index of the first occurrence of a particular value in this container.

```csharp
public static int IndexOf<T, U>(this NativeArray<T> container, U value) where T : unmanaged, IEquatable<U>
```

### Parameters

**** (\[NativeArray\<T>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): The container to search.**** (T): The value to locate.

### Returns

| Type                                                       | Description                                                                                             |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the first occurrence of the value in this container. Returns -1 if no occurrence is found. |

## IndexOf\<T, U>(ReadOnly, T)

Finds the index of the first occurrence of a particular value in this container.

```csharp
public static int IndexOf<T, U>(this NativeArray<T>.ReadOnly container, U value) where T : unmanaged, IEquatable<U>
```

### Parameters

**** (\[ReadOnly]\(/engine/6000.7/script-reference/unity/collections/nativearray1/readonly)): The container to search.**** (T): The value to locate.

### Returns

| Type                                                       | Description                                                                                             |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the first occurrence of the value in this container. Returns -1 if no occurrence is found. |

## IndexOf\<T, U>(NativeList\<T>, T)

Finds the index of the first occurrence of a particular value in this container.

```csharp
public static int IndexOf<T, U>(this NativeList<T> container, U value) where T : unmanaged, IEquatable<U>
```

### Parameters

**** (\[NativeList\<T>]\(/engine/6000.7/script-reference/unity/collections/nativelist1)): The container to search.**** (T): The value to locate.

### Returns

| Type                                                       | Description                                                                                             |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the first occurrence of the value in this container. Returns -1 if no occurrence is found. |

## IndexOf\<T, U>(\`\<>\*, int, T)

Finds the index of the first occurrence of a particular value in a buffer.

```csharp
public static int IndexOf<T, U>(T* ptr, int length, U value) where T : unmanaged, IEquatable<U>
```

### Parameters

**** (\[\<T>\*]\(./)): A buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of elements in the buffer.**** (T): The value to locate.

### Returns

| Type                                                       | Description                                                                                         |
| ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the first occurrence of the value in the buffer. Returns -1 if no occurrence is found. |

## IndexOf\<T, U>(ReadOnlySpan\<T>, T)

Finds the index of the first occurrence of a particular value in a buffer.

```csharp
public static int IndexOf<T, U>(ReadOnlySpan<T> roSpan, U value) where T : unmanaged, IEquatable<U>
```

### Parameters

**** (\[ReadOnlySpan\<T>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): A ReadOnlySpan.**** (T): The value to locate.

### Returns

| Type                                                       | Description                                                                                         |
| ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the first occurrence of the value in the buffer. Returns -1 if no occurrence is found. |
