Show / Hide Table of Contents

Class ArrayValue

Represents an array value in the virtual machine, containing a collection of values of a specified type.

Inheritance
object
ArrayValue
Implements
IValue
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
Namespace: VM.Core.ValueTypes
Assembly: VM.dll
Syntax
public class ArrayValue : IValue
Remarks

Implements the IValue interface to provide array-specific operations and conversions. Supports both initialization with existing values and creation of empty arrays of a specified size.

Constructors

ArrayValue(IEnumerable<IValue>, string)

Initializes a new instance of the ArrayValue class with the specified values.

Declaration
public ArrayValue(IEnumerable<IValue> values, string elementType = "any")
Parameters
Type Name Description
IEnumerable<IValue> values

The initial values to populate the array.

string elementType

The type of elements in the array (default: "any").

ArrayValue(int, string)

Initializes a new instance of the ArrayValue class with the specified size.

Declaration
public ArrayValue(int size, string elementType = "any")
Parameters
Type Name Description
int size

The number of elements in the array.

string elementType

The type of elements in the array (default: "any").

Remarks

All elements are initialized to NullValue.Instance.

Properties

ElementType

Gets the type of elements stored in the array.

Declaration
public string ElementType { get; }
Property Value
Type Description
string

A string representing the element type (e.g., "int", "string", "any").

Length

Gets the number of elements in the array.

Declaration
public int Length { get; }
Property Value
Type Description
int

Raw

Gets the raw underlying list of values.

Declaration
public object Raw { get; }
Property Value
Type Description
object

TypeName

Gets the type name of the array ("array").

Declaration
public string TypeName { get; }
Property Value
Type Description
string

Methods

AsBool()

Converts the array to a boolean by checking if it's non-empty.

Declaration
public bool AsBool()
Returns
Type Description
bool

true if the array has elements; otherwise, false.

AsFloat()

Converts the array to a float by returning its length.

Declaration
public float AsFloat()
Returns
Type Description
float

The number of elements in the array as a float.

AsInt()

Converts the array to an integer by returning its length.

Declaration
public int AsInt()
Returns
Type Description
int

The number of elements in the array.

AsString()

Converts the array to a string representation.

Declaration
public string AsString()
Returns
Type Description
string

A string showing all elements in the format [elem1, elem2, ...].

Get(int)

Gets the element at the specified index.

Declaration
public IValue Get(int index)
Parameters
Type Name Description
int index

The zero-based index of the element to get.

Returns
Type Description
IValue

The element at the specified index.

Exceptions
Type Condition
IndexOutOfRangeException

Thrown when the index is less than 0 or greater than or equal to the array length.

Set(int, IValue)

Sets the element at the specified index.

Declaration
public void Set(int index, IValue value)
Parameters
Type Name Description
int index

The zero-based index of the element to set.

IValue value

The value to assign to the element.

Exceptions
Type Condition
IndexOutOfRangeException

Thrown when the index is less than 0 or greater than or equal to the array length.

ToString()

Returns a string that represents the current array.

Declaration
public override string ToString()
Returns
Type Description
string

A string showing all elements in the format [elem1, elem2, ...].

Overrides
object.ToString()

Implements

IValue
In this article
Back to top Generated by DocFX