# Sort

> Sorts an array in ascending order.

## Definition

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

## Sort\<T>(\`\<>\*, int)

Sorts an array in ascending order.

```csharp
public static void Sort<T>(T* ptr, int length) where T : unmanaged, IComparable<T>
```

### Parameters

**** (\[\<T>\*]\(./)): The array to sort.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to sort in the array. Indexes greater than or equal to `length` won't be included in the sort.

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

Sorts an array using a custom comparison.

```csharp
public static void Sort<T, U>(T* ptr, int length, U comp) where T : unmanaged where U : IComparer<T>
```

### Parameters

**** (\[\<T>\*]\(./)): The array to sort.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to sort in the array. Indexes greater than or equal to `length` won't be included in the sort.**** (T): The comparison function used to determine the relative order of the elements.

## Sort\<T>(Span\<T>)

Sorts this span in ascending order.

```csharp
public static void Sort<T>(this Span<T> span) where T : unmanaged, IComparable<T>
```

### Parameters

**** (\[Span\<T>]\(https\://learn.microsoft.com/dotnet/api/system.span-1)): The span to sort.

## Sort\<T, U>(Span\<T>, T)

Sorts this span using a custom comparison.

```csharp
public static void Sort<T, U>(this Span<T> span, U comp) where T : unmanaged where U : IComparer<T>
```

### Parameters

**** (\[Span\<T>]\(https\://learn.microsoft.com/dotnet/api/system.span-1)): The span to sort.**** (T): The comparison function used to determine the relative order of the elements.

## Sort\<T>(NativeArray\<T>)

Sorts this array in ascending order.

```csharp
public static void Sort<T>(this NativeArray<T> container) where T : unmanaged, IComparable<T>
```

### Parameters

**** (\[NativeArray\<T>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): The array to sort.

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

Sorts this array using a custom comparison.

```csharp
public static void Sort<T, U>(this NativeArray<T> container, U comp) where T : unmanaged where U : IComparer<T>
```

### Parameters

**** (\[NativeArray\<T>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): The array to sort.**** (T): The comparison function used to determine the relative order of the elements.

## Sort\<T>(NativeList\<T>)

Sorts this list in ascending order.

```csharp
public static void Sort<T>(this NativeList<T> container) where T : unmanaged, IComparable<T>
```

### Parameters

**** (\[NativeList\<T>]\(/engine/6000.7/script-reference/unity/collections/nativelist1)): The list to sort.

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

Sorts this list using a custom comparison.

```csharp
public static void Sort<T, U>(this NativeList<T> container, U comp) where T : unmanaged where U : IComparer<T>
```

### Parameters

**** (\[NativeList\<T>]\(/engine/6000.7/script-reference/unity/collections/nativelist1)): The list to sort.**** (T): The comparison function used to determine the relative order of the elements.

## Sort\<T>(UnsafeList\<T>)

Sorts this list in ascending order.

```csharp
public static void Sort<T>(this UnsafeList<T> container) where T : unmanaged, IComparable<T>
```

### Parameters

**** (\[UnsafeList\<T>]\(/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1)): The list to sort.

## Sort\<T, U>(UnsafeList\<T>, T)

Sorts the list using a custom comparison.

```csharp
public static void Sort<T, U>(this UnsafeList<T> container, U comp) where T : unmanaged where U : IComparer<T>
```

### Parameters

**** (\[UnsafeList\<T>]\(/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafelist1)): The list to sort.**** (T): The comparison function used to determine the relative order of the elements.

## Sort\<T>(NativeSlice\<T>)

Sorts this slice in ascending order.

```csharp
public static void Sort<T>(this NativeSlice<T> container) where T : unmanaged, IComparable<T>
```

### Parameters

**** (\[NativeSlice\<T>]\(/engine/6000.7/script-reference/unity/collections/nativeslice1)): The slice to sort.

## Sort\<T, U>(NativeSlice\<T>, T)

Sorts this slice using a custom comparison.

```csharp
public static void Sort<T, U>(this NativeSlice<T> container, U comp) where T : unmanaged where U : IComparer<T>
```

### Parameters

**** (\[NativeSlice\<T>]\(/engine/6000.7/script-reference/unity/collections/nativeslice1)): The slice to sort.**** (T): The comparison function used to determine the relative order of the elements.
