CollectionExtensions Class
Namespace: Stride.Core.ExtensionsAssembly: Stride.Core.dll
An extension class for various types of collection.
public static class CollectionExtensions
| Name | Description | |
|---|---|---|
| Methods | ||
| GetItemOrNull<T>(IList<T>, Int32) | Gets the item from a list at a specified index. If index is out of the list, returns null. |
|
| IndexOf<T>(IReadOnlyList<T>, T) | Determines the index of a specific item in the System.Collections.Generic.IReadOnlyList<T>. |
|
| SwapRemove<T>(IList<T>, T) | Remove an item by swapping it with the last item and removing it from the last position. This function prevents to shift values from the list on removal but does not maintain order. |
|
| SwapRemoveAt<T>(IList<T>, Int32) | Remove an item by swapping it with the last item and removing it from the last position. This function prevents to shift values from the list on removal but does not maintain order. |
|
Methods
GetItemOrNull<T>(IList<T>, Int32)
Gets the item from a list at a specified index. If index is out of the list, returns null.
public static T GetItemOrNull<T>(this IList<T> list, int index)
where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IList<T> | list | The list. |
| System.Int32 | index | The index. |
Returns
| Type | Description |
|---|---|
| T | The item from a list at a specified index. If index is out of the list, returns null.. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the item in the list |
IndexOf<T>(IReadOnlyList<T>, T)
Determines the index of a specific item in the System.Collections.Generic.IReadOnlyList<T>.
public static int IndexOf<T>(this IReadOnlyList<T> list, T item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IReadOnlyList<T> | list | The list. |
| T | item | The object to locate in the System.Collections.Generic.IReadOnlyList<T>. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of item if found in the list; otherwise, -1. |
Type Parameters
| Name | Description |
|---|---|
| T |
SwapRemove<T>(IList<T>, T)
Remove an item by swapping it with the last item and removing it from the last position. This function prevents to shift values from the list on removal but does not maintain order.
public static void SwapRemove<T>(this IList<T> list, T item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IList<T> | list | The list. |
| T | item | The item to remove. |
Type Parameters
| Name | Description |
|---|---|
| T |
SwapRemoveAt<T>(IList<T>, Int32)
Remove an item by swapping it with the last item and removing it from the last position. This function prevents to shift values from the list on removal but does not maintain order.
public static void SwapRemoveAt<T>(this IList<T> list, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IList<T> | list | The list. |
| System.Int32 | index | Index of the item to remove. |
Type Parameters
| Name | Description |
|---|---|
| T |