reckfellENGINE

Reckfell.Collections.Array

An engine Variant collection for C#: count, copying and distinction from T[].

On this page
class Reckfell.Collections.ArrayReckfellSharp

A C# class in Reckfell.Collections wrapping an engine array of Variant values. Used at the engine API boundary; it differs from a C# T[] array or List<T>. Reckfell.Collections.Array<T> provides a typed engine collection.

Variable assignment copies the collection reference, not its elements. Duplicate() creates a separate top-level collection; nested copying is controlled by deep. Do not assume references to engine objects are automatically cloned.

There is no C# conversion to bool. Test the element count through Count, for example array.Count > 0. If the variable can be null, first check array is not null. An empty collection and a missing reference are different states.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors10

Array10 overloads
# Array · 1/10
C#
public Array();

Constructs an array from a Vector4[].

# Array · 2/10
C#
public Array(Variant[] array);

Constructs an array from a Vector4[].

Parameters
NameTypeDefault
arrayVariant[]—
array

The objects to put in the new array.

# Array · 3/10
C#
public Array(System.Collections.Generic.IEnumerable<Variant> collection);

Constructs an array from a Vector4[].

Parameters
NameTypeDefault
collectionSystem.Collections.Generic.IEnumerable<Variant>—
collection

The collection of elements to construct from.

# Array · 4/10
C#
public Array(ReadOnlySpan<EntityPath> span);

Constructs an array from a Vector4[].

Parameters
NameTypeDefault
spanReadOnlySpan<EntityPath>—
# Array · 5/10
C#
public Array(ReadOnlySpan<ReckfellObject> span);

Constructs an array from a Vector4[].

Parameters
NameTypeDefault
spanReadOnlySpan<ReckfellObject>—
# Array · 6/10
C#
public Array(ReadOnlySpan<Rid> span);

Constructs an array from a Vector4[].

Parameters
NameTypeDefault
spanReadOnlySpan<Rid>—
# Array · 7/10
C#
public Array(ReadOnlySpan<StringName> span);

Constructs an array from a Vector4[].

Parameters
NameTypeDefault
spanReadOnlySpan<StringName>—
# Array · 8/10
C#
public Array(Span<EntityPath> span);

Constructs an array from a Vector4[].

Parameters
NameTypeDefault
spanSpan<EntityPath>—
# Array · 9/10
C#
public Array(Span<Rid> span);

Constructs an array from a Vector4[].

Parameters
NameTypeDefault
spanSpan<Rid>—
# Array · 10/10
C#
public Array(Span<StringName> span);

Constructs an array from a Vector4[].

Parameters
NameTypeDefault
spanSpan<StringName>—

Properties3

CountProperty
# Count
C#
public int Count { get; }

Returns the number of times an element is in the array. To count how many elements in an array satisfy a condition, see reduce.

IsReadOnlyProperty
# IsReadOnly
C#
public bool IsReadOnly { get; }

Returns true if the array is read-only. See Reckfell.Collections.Array.MakeReadOnly. In C#, arrays are automatically read-only if declared with the const keyword.

ItemProperty
# Item
C#
public Variant this[int index] { get; set; }

Reads a copy of the native Variant at the index or replaces the element with a copy of the assigned value. A copied container value can still share its container contents; the index must be within Count.

Methods35

Addvoid
# Add
C#
public void Add(Variant item);

Adds an item to the end of this Reckfell.Collections.Array. This is the same as append or push_back in ExcludedScript.

Parameters
NameTypeDefault
itemVariant—
item

The Variant item to add.

AddRange3 overloads
# AddRange · 1/3
C#
public void AddRange<T>(System.Collections.Generic.IEnumerable<T> collection);

Adds the elements of the specified collection to the end of this Reckfell.Collections.Array.

Parameters
NameTypeDefault
collectionSystem.Collections.Generic.IEnumerable<T>—
collection

Collection of Variant items to add.

# AddRange · 2/3
C#
public void AddRange<T>(ReadOnlySpan<T> span);

Adds the elements of the specified collection to the end of this Reckfell.Collections.Array.

Parameters
NameTypeDefault
spanReadOnlySpan<T>—
span

The span of Variant items to add.

# AddRange · 3/3
C#
public void AddRange<T>(T[] array);

Adds the elements of the specified array to the end of this Reckfell.Collections.Array.

Parameters
NameTypeDefault
arrayT[]—
array

The array of Variant items to add.

BinarySearch2 overloads
# BinarySearch · 1/2
C#
public int BinarySearch(Variant item);

Finds the index of an existing value using binary search. If the value is not present in the array, it returns the bitwise complement of the insertion index that maintains sorting order. Note: Calling Reckfell.Collections.Array.BinarySearch on an unsorted array results in unexpected behavior.

Parameters
NameTypeDefault
itemVariant—
item

The object to locate.

Returns int

The index of the item in the array, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item or, if there is no larger element, the bitwise complement of Reckfell.Collections.Array.Count.

# BinarySearch · 2/2
C#
public int BinarySearch(int index, int count, Variant item);

Finds the index of an existing value using binary search. If the value is not present in the array, it returns the bitwise complement of the insertion index that maintains sorting order. Note: Calling Reckfell.Collections.Array.BinarySearch on an unsorted array results in unexpected behavior.

Parameters
NameTypeDefault
indexint—
countint—
itemVariant—
index

The starting index of the range to search.

count

The length of the range to search.

item

The object to locate.

Returns int

The index of the item in the array, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item or, if there is no larger element, the bitwise complement of Reckfell.Collections.Array.Count.

Clearvoid
# Clear
C#
public void Clear();

Removes all elements from the array. This is equivalent to using Reckfell.Collections.Array.Resize with a size of 0.

Containsbool
# Contains
C#
public bool Contains(Variant item);

Returns true if the array contains the given value.

Parameters
NameTypeDefault
itemVariant—
item

The Variant item to look for.

Returns bool

Whether or not this array contains the given item.

CopyTovoid
# CopyTo
C#
public void CopyTo(Variant[] array, int arrayIndex);

Copies the elements of this Reckfell.Collections.Array to the given Variant C# array, starting at the given index.

Parameters
NameTypeDefault
arrayVariant[]—
arrayIndexint—
array

The array to copy to.

arrayIndex

The index to start at.

Dispose2 overloads
# Dispose · 1/2
C#
public void Dispose();

Disposes of this Reckfell.Collections.Array.

# Dispose · 2/2
C#
public void Dispose(bool disposing);
Parameters
NameTypeDefault
disposingbool—
DuplicateReckfell.Collections.Array
# Duplicate
C#
public Reckfell.Collections.Array Duplicate(bool deep = false);

Creates a new outer Array. With deep=false nested arrays/dictionaries remain shared; deep=true copies nested containers but does not clone contained engine objects.

Parameters
NameTypeDefault
deepboolfalse
deep

Whether to copy nested containers. Engine objects remain references in either case.

Returns Reckfell.Collections.Array

New outer Array with the chosen container-copy depth.

Fillvoid
# Fill
C#
public void Fill(Variant value);

Assigns the given value to all elements in the array. This method can often be combined with Reckfell.Collections.Array.Resize to create an array with a given size and initialized elements:

C#
Reckfell.Collections.Array array = [];
array.Resize(5);
array.Fill(2);
ReckfellApi.Print(array); // Prints [2, 2, 2, 2, 2]

Note: If value is a Variant passed by reference (ReckfellObject-derived, Reckfell.Collections.Array, Reckfell.Collections.Dictionary, etc.), the array will be filled with references to the same value, which are not duplicates.

Parameters
NameTypeDefault
valueVariant—
value

The value to fill the array with.

GetEnumeratorSystem.Collections.Generic.IEnumerator<Variant>
# GetEnumerator
C#
public System.Collections.Generic.IEnumerator<Variant> GetEnumerator();

Gets an enumerator for this Reckfell.Collections.Array.

Returns System.Collections.Generic.IEnumerator<Variant>

An enumerator.

GetSliceRangeReckfell.Collections.Array
# GetSliceRange
C#
public Reckfell.Collections.Array GetSliceRange(int start, int end, int step = 1, bool deep = false);

Returns the slice of the Reckfell.Collections.Array, from start (inclusive) to end (exclusive), as a new Reckfell.Collections.Array. The absolute value of start and end will be clamped to the array size. If either start or end are negative, they will be relative to the end of the array (i.e. arr.GetSliceRange(0, -2) is a shorthand for arr.GetSliceRange(0, arr.Count - 2)). If specified, step is the relative index between source elements. It can be negative, then start must be higher than end. For example, [0, 1, 2, 3, 4, 5].GetSliceRange(5, 1, -2) returns [5, 3]. If deep is true, each element will be copied by value rather than by reference.

Parameters
NameTypeDefault
startint—
endint—
stepint1
deepboolfalse
start

The zero-based index at which the range starts.

end

The zero-based index at which the range ends.

step

The relative index between source elements to take.

deep

If true, performs a deep copy.

Returns Reckfell.Collections.Array

A new array that contains the elements inside the slice range.

IndexOf2 overloads
# IndexOf · 1/2
C#
public int IndexOf(Variant item);

Searches the array for a value and returns its index or -1 if not found.

Parameters
NameTypeDefault
itemVariant—
item

The Variant item to search for.

Returns int

The index of the item, or -1 if not found.

# IndexOf · 2/2
C#
public int IndexOf(Variant item, int index);

Searches the array for a value and returns its index or -1 if not found.

Parameters
NameTypeDefault
itemVariant—
indexint—
item

The Variant item to search for.

index

The initial search index to start from.

Returns int

The index of the item, or -1 if not found.

Insertvoid
# Insert
C#
public void Insert(int index, Variant item);

Inserts a new element (value) at a given index (position) in the array. position should be between 0 and the array's size. If negative, position is considered relative to the end of the array. Returns OK on success, or one of the other Error constants if this method fails. Note: Every element's index after position needs to be shifted forward, which may have a noticeable performance cost, especially on larger arrays.

Parameters
NameTypeDefault
indexint—
itemVariant—
index

The index to insert at.

item

The Variant item to insert.

LastIndexOf2 overloads
# LastIndexOf · 1/2
C#
public int LastIndexOf(Variant item);

Searches the array for a value in reverse order and returns its index or -1 if not found.

Parameters
NameTypeDefault
itemVariant—
item

The Variant item to search for.

Returns int

The index of the item, or -1 if not found.

# LastIndexOf · 2/2
C#
public int LastIndexOf(Variant item, int index);

Searches the array for a value in reverse order and returns its index or -1 if not found.

Parameters
NameTypeDefault
itemVariant—
indexint—
item

The Variant item to search for.

index

The initial search index to start from.

Returns int

The index of the item, or -1 if not found.

MakeReadOnlyvoid
# MakeReadOnly
C#
public void MakeReadOnly();

Makes the array read-only. The array's elements cannot be overridden with different values, and their order cannot change. Does not apply to nested elements, such as dictionaries. In C#, arrays are automatically read-only if declared with the const keyword.

MaxVariant
# Max
C#
public Variant Max();

Returns the maximum value contained in the array, if all elements can be compared. Otherwise, returns null. See also Reckfell.Collections.Array.Min. To find the maximum value using a custom comparator, you can use reduce.

Returns Variant

The maximum value contained in the array.

MinVariant
# Min
C#
public Variant Min();

Returns the minimum value contained in the array, if all elements can be compared. Otherwise, returns null. See also Reckfell.Collections.Array.Max.

Returns Variant

The minimum value contained in the array.

PickRandomVariant
# PickRandom
C#
public Variant PickRandom();

Returns a random element from the array. Generates an error and returns null if the array is empty.

C#
Reckfell.Collections.Array array = [1, 2, 3.25f, "Hi"];
ReckfellApi.Print(array.PickRandom()); // May print 1, 2, 3.25, or "Hi".

Note: Like many similar functions in the engine (such as ReckfellApi.Randi or Reckfell.Collections.Array.Shuffle), this method uses a common, global random seed. To get a predictable outcome from this method, see ReckfellApi.Seed.

Returns Variant

A random element from the array.

RecursiveEqualbool
# RecursiveEqual
C#
public bool RecursiveEqual(Reckfell.Collections.Array other);

Compares this Reckfell.Collections.Array against the other Reckfell.Collections.Array recursively. Returns true if the sizes and contents of the arrays are equal, false otherwise.

Parameters
NameTypeDefault
otherReckfell.Collections.Array—
other

The other array to compare against.

Returns bool

true if the sizes and contents of the arrays are equal, false otherwise.

Removebool
# Remove
C#
public bool Remove(Variant item);

Removes the first occurrence of the specified item from this Reckfell.Collections.Array.

Parameters
NameTypeDefault
itemVariant—
item

The value to remove.

Returns bool
RemoveAtvoid
# RemoveAt
C#
public void RemoveAt(int index);

Removes the element from the array at the given index (position). If the index is out of bounds, this method fails. If the index is negative, position is considered relative to the end of the array. If you need to return the removed element, use pop_at. To remove an element by value, use erase instead. Note: This method shifts every element's index after position back, which may have a noticeable performance cost, especially on larger arrays.

Parameters
NameTypeDefault
indexint—
index

The index of the element to remove.

ResizeError
# Resize
C#
public Error Resize(int newSize);

Sets the array's number of elements to size. If size is smaller than the array's current size, the elements at the end are removed. If size is greater, new default elements (usually null) are added, depending on the array's type. Returns OK on success, or one of the following Error constants if this method fails: ERR_LOCKED if the array is read-only, ERR_INVALID_PARAMETER if the size is negative, or ERR_OUT_OF_MEMORY if allocations fail. Use size to find the actual size of the array after resize. Note: Calling this method once and assigning the new values is faster than calling append for every new element.

Parameters
NameTypeDefault
newSizeint—
newSize

The new size of the array.

Returns Error

Error.Ok if successful, or an error code.

Reversevoid
# Reverse
C#
public void Reverse();

Reverses the order of all elements in the array.

Shufflevoid
# Shuffle
C#
public void Shuffle();

Shuffles all elements of the array in a random order. Note: Like many similar functions in the engine (such as ReckfellApi.Randi or Reckfell.Collections.Array.PickRandom), this method uses a common, global random seed. To get a predictable outcome from this method, see ReckfellApi.Seed.

Slice2 overloads
# Slice · 1/2
C#
public Reckfell.Collections.Array Slice(int start);

Returns a new Reckfell.Collections.Array containing this array's elements, from index begin (inclusive) to end (exclusive), every step elements. If either begin or end are negative, their value is relative to the end of the array. If step is negative, this method iterates through the array in reverse, returning a slice ordered backwards. For this to work, begin must be greater than end. If deep is true, all nested Reckfell.Collections.Array and Reckfell.Collections.Dictionary elements in the slice are duplicated from the original, recursively. See also Reckfell.Collections.Array.Duplicate.

Parameters
NameTypeDefault
startint—
start

The zero-based index at which the range starts.

Returns Reckfell.Collections.Array

A new array that contains the elements inside the slice range.

# Slice · 2/2
C#
public Reckfell.Collections.Array Slice(int start, int length);

Returns a new Reckfell.Collections.Array containing this array's elements, from index begin (inclusive) to end (exclusive), every step elements. If either begin or end are negative, their value is relative to the end of the array. If step is negative, this method iterates through the array in reverse, returning a slice ordered backwards. For this to work, begin must be greater than end. If deep is true, all nested Reckfell.Collections.Array and Reckfell.Collections.Dictionary elements in the slice are duplicated from the original, recursively. See also Reckfell.Collections.Array.Duplicate.

Parameters
NameTypeDefault
startint—
lengthint—
start

The zero-based index at which the range starts.

length

The length of the range.

Returns Reckfell.Collections.Array

A new array that contains the elements inside the slice range.

Sortvoid
# Sort
C#
public void Sort();

Sorts the array in ascending order. The final order is dependent on the "less than" (<) comparison between elements.

C#
Reckfell.Collections.Array numbers = [10, 5, 2.5, 8];
numbers.Sort();
ReckfellApi.Print(numbers); // Prints [2.5, 5, 8, 10]

Note: The sorting algorithm used is not stable. This means that equivalent elements (such as 2 and 2.0) may have their order changed when calling Reckfell.Collections.Array.Sort.

ToStringstring
# ToString
C#
public override string ToString();

Converts this Reckfell.Collections.Array to a string.

Returns string

A string representation of this array.

op_AdditionReckfell.Collections.Array
# op_Addition
C#
public static Reckfell.Collections.Array operator +(Reckfell.Collections.Array left, Reckfell.Collections.Array right);

Concatenates two Reckfell.Collections.Arrays together, with the right being added to the end of the Reckfell.Collections.Array specified in left. For example, [1, 2] + [3, 4] results in [1, 2, 3, 4].

Parameters
NameTypeDefault
leftReckfell.Collections.Array—
rightReckfell.Collections.Array—
left

The first array.

right

The second array.

Returns Reckfell.Collections.Array

A new Reckfell Array with the contents of both arrays.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.