Search Results for

    Show / Hide Table of Contents

    Class ArrayUtils

    The utility class for arrays

    Inheritance
    System.Object
    ArrayUtils
    Namespace: black.kit.toybox
    Assembly: cs.temp.dll.dll
    Syntax
    public static class ArrayUtils

    Methods

    At<T>(T[], Int32)

    Returns the element at the specified index in the array.

    Declaration
    public static T At<T>(this T[] array, int index)
    Parameters
    Type Name Description
    T[] array

    The array. If the array is null, returns the default value.

    System.Int32 index

    The index of the element to obtain

    Returns
    Type Description
    T

    The element at the specified index in the array. If null, the default value of the type.

    Type Parameters
    Name Description
    T

    Type of array elements

    Remarks

    If the specified index is negative, elements counted from the end are obtained. And also, If the specified index is outside the range, the elements within the range are obtained by calculating the remainder.

    Examples
    int[] array = { 1, 2, 3 };
    array.At(0); // 1
    array.At(1); // 2
    array.At(2); // 3
    array.At(3); // 1
    array.At(-1); // 3
    array.At(-2); // 2
    array.At(-3); // 1
    array.At(-4); // 3

    AtIndex<T>(T[], Int32)

    Returns the index at the specified index in the array.

    Declaration
    public static int AtIndex<T>(this T[] array, int index)
    Parameters
    Type Name Description
    T[] array

    The array. If the array is null, returns the negative value.

    System.Int32 index

    The index of the element to obtain

    Returns
    Type Description
    System.Int32

    The index at the specified index in the array. If array is null, the negative value of the type.

    Type Parameters
    Name Description
    T

    Type of array elements

    Remarks

    If the specified index is negative, elements counted from the end are obtained. And also, If the specified index is outside the range, the elements within the range are obtained by calculating the remainder.

    Examples
    int[] array = { 1, 2, 3 };
    array.AtIndex(0); // 0
    array.AtIndex(1); // 1
    array.AtIndex(2); // 2
    array.AtIndex(3); // 0
    array.AtIndex(-1); // 2
    array.AtIndex(-2); // 1
    array.AtIndex(-3); // 0
    array.AtIndex(-4); // 2

    Contains<T>(T[], T)

    Determines whether the specified array contains the specified value.

    Declaration
    public static bool Contains<T>(this T[] array, T value)
        where T : IEquatable<T>
    Parameters
    Type Name Description
    T[] array

    The array. If the array is null, returns false.

    T value

    The value to contains

    Returns
    Type Description
    System.Boolean

    True if the specified array contains the specified value. Otherwise, false.

    Type Parameters
    Name Description
    T

    Type of array elements

    Examples
    int[] array = { 1, 2, 3 };
    array.Contains(2); // true
    array.Contains(4); // false

    Fill<T>(T[], T)

    Fill the array with the specified value.

    Declaration
    public static void Fill<T>(this T[] array, T value)
    Parameters
    Type Name Description
    T[] array

    The array to fill

    T value

    The value to fill the array with

    Type Parameters
    Name Description
    T

    Type of array elements

    Examples
    int[] array = { 1, 2, 3 };
    array.Fill(0); // { 0, 0, 0 }
    array.Fill(1); // { 1, 1, 1 }
    array.Fill(2); // { 2, 2, 2 }
    array.Fill(3); // { 3, 3, 3 }
    array.Fill(4); // { 4, 4, 4 }

    IsFill<T>(T[])

    Determines whether the specified array is filled with the same value.

    Declaration
    public static bool IsFill<T>(this T[] array)
        where T : IEquatable<T>
    Parameters
    Type Name Description
    T[] array

    The array to check

    Returns
    Type Description
    System.Boolean

    True if the array is filled with the same value, otherwise false.

    Type Parameters
    Name Description
    T

    Type of array elements

    Examples
    int[] arrayA = { 1, 1, 1 };
    int[] arrayB = { 1, 2, 2 };
    int[] arrayC = { 2, 2, 2 };
    int[] arrayD = new int[0];
    arrayA.IsFill(); // true
    arrayB.IsFill(); // false
    arrayC.IsFill(); // true
    arrayD.IsFill(); // false

    IsFill<T>(T[], T)

    Determines whether the specified array is filled with the specified value.

    Declaration
    public static bool IsFill<T>(this T[] array, T value)
        where T : IEquatable<T>
    Parameters
    Type Name Description
    T[] array

    The array to check

    T value

    The value to compare against

    Returns
    Type Description
    System.Boolean

    True if the array is filled with the specified value, otherwise false.

    Type Parameters
    Name Description
    T

    Type of array elements

    Examples
    int[] arrayA = { 1, 1, 1 };
    int[] arrayB = { 1, 2, 2 };
    int[] arrayC = { 2, 2, 2 };
    arrayA.IsFill(1); // true
    arrayA.IsFill(2); // false
    arrayB.IsFill(1); // false
    arrayB.IsFill(2); // false
    arrayC.IsFill(1); // false
    arrayC.IsFill(2); // true

    SetActive(GameObject[], Boolean)

    Batch setting of game object activation status.

    Declaration
    public static void SetActive(this GameObject[] array, bool active)
    Parameters
    Type Name Description
    GameObject[] array

    Array of game objects. If the array is null, do nothing.

    System.Boolean active

    New activation status

    Remarks

    If the elements contain null or invalid, it is ignored, but we recommend removing them for performance reasons.

    Examples
    [SerializeField] private GameObject[] objects;
    [SerializeField] private Toggle toggle;
    
    public void OnValueChanged() => objects.SetActive(toggle.isOn);
    In This Article
    Back to top Example Unity documentation