Reckfell.Collections.Array
An engine Variant collection for C#: count, copying and distinction from T[].
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
public Array();Constructs an array from a Vector4[].
public Array(Variant[] array);Constructs an array from a Vector4[].
| Name | Type | Default |
|---|---|---|
array | Variant[] | — |
arrayThe objects to put in the new array.
public Array(System.Collections.Generic.IEnumerable<Variant> collection);Constructs an array from a Vector4[].
| Name | Type | Default |
|---|---|---|
collection | System.Collections.Generic.IEnumerable<Variant> | — |
collectionThe collection of elements to construct from.
public Array(ReadOnlySpan<EntityPath> span);Constructs an array from a Vector4[].
| Name | Type | Default |
|---|---|---|
span | ReadOnlySpan<EntityPath> | — |
public Array(ReadOnlySpan<ReckfellObject> span);Constructs an array from a Vector4[].
| Name | Type | Default |
|---|---|---|
span | ReadOnlySpan<ReckfellObject> | — |
public Array(ReadOnlySpan<Rid> span);Constructs an array from a Vector4[].
| Name | Type | Default |
|---|---|---|
span | ReadOnlySpan<Rid> | — |
public Array(ReadOnlySpan<StringName> span);Constructs an array from a Vector4[].
| Name | Type | Default |
|---|---|---|
span | ReadOnlySpan<StringName> | — |
public Array(Span<EntityPath> span);Constructs an array from a Vector4[].
| Name | Type | Default |
|---|---|---|
span | Span<EntityPath> | — |
public Array(Span<Rid> span);Constructs an array from a Vector4[].
| Name | Type | Default |
|---|---|---|
span | Span<Rid> | — |
public Array(Span<StringName> span);Constructs an array from a Vector4[].
| Name | Type | Default |
|---|---|---|
span | Span<StringName> | — |
Properties3
CountProperty
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
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
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
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.
| Name | Type | Default |
|---|---|---|
item | Variant | — |
itemThe Variant item to add.
AddRange3 overloads
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.
| Name | Type | Default |
|---|---|---|
collection | System.Collections.Generic.IEnumerable<T> | — |
collectionCollection of Variant items to add.
public void AddRange<T>(ReadOnlySpan<T> span);Adds the elements of the specified collection to the end of this Reckfell.Collections.Array.
| Name | Type | Default |
|---|---|---|
span | ReadOnlySpan<T> | — |
spanThe span of Variant items to add.
public void AddRange<T>(T[] array);Adds the elements of the specified array to the end of this Reckfell.Collections.Array.
| Name | Type | Default |
|---|---|---|
array | T[] | — |
arrayThe array of Variant items to add.
BinarySearch2 overloads
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.
| Name | Type | Default |
|---|---|---|
item | Variant | — |
itemThe object to locate.
intThe 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.
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.
| Name | Type | Default |
|---|---|---|
index | int | — |
count | int | — |
item | Variant | — |
indexThe starting index of the range to search.
countThe length of the range to search.
itemThe object to locate.
intThe 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
public void Clear();Removes all elements from the array. This is equivalent to using Reckfell.Collections.Array.Resize with a size of 0.
Containsbool
public bool Contains(Variant item);Returns true if the array contains the given value.
| Name | Type | Default |
|---|---|---|
item | Variant | — |
itemThe Variant item to look for.
boolWhether or not this array contains the given item.
CopyTovoid
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.
| Name | Type | Default |
|---|---|---|
array | Variant[] | — |
arrayIndex | int | — |
arrayThe array to copy to.
arrayIndexThe index to start at.
Dispose2 overloads
public void Dispose();Disposes of this Reckfell.Collections.Array.
public void Dispose(bool disposing);| Name | Type | Default |
|---|---|---|
disposing | bool | — |
DuplicateReckfell.Collections.Array
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.
| Name | Type | Default |
|---|---|---|
deep | bool | false |
deepWhether to copy nested containers. Engine objects remain references in either case.
Reckfell.Collections.ArrayNew outer Array with the chosen container-copy depth.
Fillvoid
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:
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.
| Name | Type | Default |
|---|---|---|
value | Variant | — |
valueThe value to fill the array with.
GetEnumeratorSystem.Collections.Generic.IEnumerator<Variant>
public System.Collections.Generic.IEnumerator<Variant> GetEnumerator();Gets an enumerator for this Reckfell.Collections.Array.
System.Collections.Generic.IEnumerator<Variant>An enumerator.
GetSliceRangeReckfell.Collections.Array
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.
| Name | Type | Default |
|---|---|---|
start | int | — |
end | int | — |
step | int | 1 |
deep | bool | false |
startThe zero-based index at which the range starts.
endThe zero-based index at which the range ends.
stepThe relative index between source elements to take.
deepIf true, performs a deep copy.
Reckfell.Collections.ArrayA new array that contains the elements inside the slice range.
IndexOf2 overloads
public int IndexOf(Variant item);Searches the array for a value and returns its index or -1 if not found.
| Name | Type | Default |
|---|---|---|
item | Variant | — |
itemThe Variant item to search for.
intThe index of the item, or -1 if not found.
public int IndexOf(Variant item, int index);Searches the array for a value and returns its index or -1 if not found.
| Name | Type | Default |
|---|---|---|
item | Variant | — |
index | int | — |
itemThe Variant item to search for.
indexThe initial search index to start from.
intThe index of the item, or -1 if not found.
Insertvoid
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.
| Name | Type | Default |
|---|---|---|
index | int | — |
item | Variant | — |
indexThe index to insert at.
itemThe Variant item to insert.
LastIndexOf2 overloads
public int LastIndexOf(Variant item);Searches the array for a value in reverse order and returns its index
or -1 if not found.
| Name | Type | Default |
|---|---|---|
item | Variant | — |
itemThe Variant item to search for.
intThe index of the item, or -1 if not found.
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.
| Name | Type | Default |
|---|---|---|
item | Variant | — |
index | int | — |
itemThe Variant item to search for.
indexThe initial search index to start from.
intThe index of the item, or -1 if not found.
MakeReadOnlyvoid
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
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.
VariantThe maximum value contained in the array.
MinVariant
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.
VariantThe minimum value contained in the array.
PickRandomVariant
public Variant PickRandom();Returns a random element from the array. Generates an error and returns null if the array is empty.
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.
VariantA random element from the array.
RecursiveEqualbool
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.
| Name | Type | Default |
|---|---|---|
other | Reckfell.Collections.Array | — |
otherThe other array to compare against.
booltrue if the sizes and contents of the arrays are equal,
false otherwise.
Removebool
public bool Remove(Variant item);Removes the first occurrence of the specified item
from this Reckfell.Collections.Array.
| Name | Type | Default |
|---|---|---|
item | Variant | — |
itemThe value to remove.
boolRemoveAtvoid
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.
| Name | Type | Default |
|---|---|---|
index | int | — |
indexThe index of the element to remove.
ResizeError
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.
| Name | Type | Default |
|---|---|---|
newSize | int | — |
newSizeThe new size of the array.
Reversevoid
public void Reverse();Reverses the order of all elements in the array.
Shufflevoid
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
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.
| Name | Type | Default |
|---|---|---|
start | int | — |
startThe zero-based index at which the range starts.
Reckfell.Collections.ArrayA new array that contains the elements inside the slice range.
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.
| Name | Type | Default |
|---|---|---|
start | int | — |
length | int | — |
startThe zero-based index at which the range starts.
lengthThe length of the range.
Reckfell.Collections.ArrayA new array that contains the elements inside the slice range.
Sortvoid
public void Sort();Sorts the array in ascending order. The final order is dependent on the "less than" (<) comparison between elements.
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
public override string ToString();Converts this Reckfell.Collections.Array to a string.
stringA string representation of this array.
op_AdditionReckfell.Collections.Array
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].
| Name | Type | Default |
|---|---|---|
left | Reckfell.Collections.Array | — |
right | Reckfell.Collections.Array | — |
leftThe first array.
rightThe second array.
Reckfell.Collections.ArrayA new Reckfell Array with the contents of both arrays.