============================== NutArrayUtils and NutListUtils ============================== Overview -------- * :ref:`Append` * :ref:`Insert and RemoveAt` * :ref:`MoveUp and MoveDown` * :ref:`OffsetUp and OffsetDown` * :ref:`Get Help <**GET HELP**>` **UTILITIES** ------------- Append ------ * ``Append(ref T[] array, T item)`` Adds an item to the end of the array. .. note:: ArrayUtils-only content. Equivalent to ``List.Add``. .. code-block:: csharp :linenos: using NutTools.Utilities; using UnityEngine; public class MyClass: MonoBehaviour { string[] array = { "Text 0", "Text 1", "Text 2", "Text 3", "Text 4", "Text 5" }; void MyMethod() { // Array is set to // [ "Text 0", "Text 1", "Text 2", "Text 3", "Text 4", "Text 5", "Text 6" ] NutArrayUtils.Append(ref array, "Text 6"); } } Insert and RemoveAt ------------------- * ``Insert(ref T[] array, T item, int index)`` * ``RemoveAt(ref T[] array, int index)`` **Insert** adds an item in the specified index, and moves all items in the array one index lower, expanding the array by one. **RemoveAt** removes the item at the specified index, moves all lower items in the array one index up, and shrinks the array. .. note:: ArrayUtils-only content. Equivalent to ``List.Insert()`` and ``List.RemoveAt()`` for arrays, respectively. .. code-block:: csharp :linenos: using NutTools.Utilities; using UnityEngine; public class MyClass: MonoBehaviour { string[] array = { "Text 0", "Text 1", "Text 2", "Text 3", "Text 4", "Text 5" }; void MyMethod() { // Array is set to // [ "Text 0", "Text 1", "Text 2", "Inserted Text", "Text 3", "Text 4", "Text 5" ] NutArrayUtils.Insert(ref array, "Inserted Text", 3); // Array is set to // [ "Text 0", "Text 1", "Text 2", "Text 3", "Text 4", "Text 5" ] NutArrayUtils.RemoveAt(ref array, 3); } } MoveUp and MoveDown ------------------- * ``MoveUp(ref T[]/List array, int index)`` * ``MoveDown(ref T[]/List array, int index)`` **MoveUp** swaps the item at index with the one an index above. If index is 0, the item will be swapped with the last entry in the array. **MoveDown** swaps the item at index with the one an index below. If index is array.Length - 1 (the last index), the item will be swapped with the first entry in the array. .. code-block:: csharp :linenos: using NutTools.Utilities; using UnityEngine; public class MyClass: MonoBehaviour { string[] array = { "Text 0", "Text 1", "Text 2", "Text 3", "Text 4", "Text 5" }; List list = new List() { "Text 0", "Text 1", "Text 2", "Text 3", "Text 4", "Text 5" }; void MyMethod() { // Array is set to // [ "Text 0", "Text 2", "Text 1", "Text 3", "Text 4", "Text 5" ] NutArrayUtils.MoveUp(ref array, 2); // List is set to // [ "Text 0", "Text 1", "Text 3", "Text 2", "Text 4", "Text 5" ] NutListUtils.MoveDown(ref list, 2); } } OffsetUp and OffsetDown ----------------------- * ``OffsetUp(ref T[]/List array, int steps)`` * ``OffsetDown(ref T[]/List array, int steps)`` **OffsetUp** moves all values up on the array as many times as specified. **OffsetDown** moves all items down on the array as many times as specified. .. code-block:: csharp :linenos: using NutTools; using UnityEngine; public class MyClass: MonoBehaviour { string[] array = { "Text 0", "Text 1", "Text 2", "Text 3", "Text 4", "Text 5" }; List list = new List() { "Text 0", "Text 1", "Text 2", "Text 3", "Text 4", "Text 5" }; void MyMethod() { // Array is set to // [ "Text 1", "Text 2", "Text 3", "Text 4", "Text 5", "Text 0" ] NutArrayUtils.OffsetUp(ref array); // List is set to // [ "Text 4", "Text 5", "Text 0", "Text 1", "Text 2", "Text 3" ] NutListUtils.OffsetDown(ref list, 2); } } **** **GET HELP** ------------ `Join this Discord server `_ to get help from the community, suggest new features, and vote on future updates! .. seealso:: * `Collections `_ * `LINQ `_ * `Arrays `_ * `System.Array `_ * :ref:`NutColorUtils ` * :ref:`NutIOUtils ` * :ref:`NutLogUtils ` * :ref:`NutTextureUtils `