PerlSharp : Perl Namespace
Array

This type represents a Perl array.

[System.Reflection.DefaultMember(MemberName="Item")]
public class Array : Value, IList, ICollection, IEnumerable

Remarks
This class has three general uses:

The following example gets a wrapper around the array named "@array" in the Perl interpreter's context. It then adds some values into the array and displays its contents using Eval.

C# Example
Interpreter perl = new Interpreter();

Array a = perl.GetArray("array");

for (int i = 0; i < 3; i++) {
	a.Add((double)i/4);
	Console.WriteLine("The Array Has: {0}", perl.Eval("join(', ', @array)"));
}
			
Members

See Also: Inherited members from Value.

Constructors
Array(Interpreter)
Creates a new, empty array in the given context.
Array(Interpreter, Value[] )
Creates a new array in the given context containing the given array of values.
Array(Interpreter, object[] )
Creates a new array in the given context containing the given array of values.
Properties
Count [read-only]
int. Returns the number of elements in the array.
Item[int]
Value. Returns an element in the array.
Methods
Add(object) : int
Pushes the object onto the array.
AddRange(ICollection)
Pushes the elements of a collection onto the array.
Clear()
Clears the contents of the Array.
Contains(Value) : bool
Returns whether the array contains the value.
Contains(object) : bool
Returns whether the array contains the object.
Delete(int) : Value
Removes the first instance of an item from within the array.
IndexOf(Value) : int
Returns the first index of the value in the array, or -1 if it is not in the array.
IndexOf(object) : int
Returns the first index of the object in the array, or -1 if it is not in the array.
IsSet(int) : bool
Tests whether an element is defined (versus undef).
Pop() : Value
Pops the last Value off the end of the Array.
Push(Value)
Pushes a value onto the end of the Array.
Remove(object)
Removes the first instance of an object from the array.
SetSize(int)
Ensures that the array has a given number of elements.
Shift() : Value
Removes the first item from the array and shifts the array down.
Unshift(int)
Shifts the elements of the Array down, making room at the start of the Array.
Unshift(Value)
Pushes a Value into the start of the array.
Unshift(Value[] )
Pushes Values into the start of the array.
Member Details
Array Constructor
public Array (Interpreter context)

Creates a new, empty array in the given context.

Parameters
context
The context that will contain the Array.

Array Constructor
public Array (Interpreter context, Value[] values)

Creates a new array in the given context containing the given array of values.

Parameters
context
The context that will contain the Array.
values
An array of values.

Array Constructor
public Array (Interpreter context, object[] values)

Creates a new array in the given context containing the given array of values.

Parameters
context
The context that will contain the Array.
values
An array of objects that will be converted to Value objects.

Clear
public void Clear ()

Clears the contents of the Array.


Delete
public Value Delete (int index)

Removes the first instance of an item from within the array.

Parameters
index
The index of the item to remove.
Returns
The removed item.
Remarks
Items in the Array after index are shifted down.

IsSet
public bool IsSet (int index)

Tests whether an element is defined (versus undef).

Parameters
index
The index of the element to test.
Returns
Whether the element is defined (not undef).

SetSize
public void SetSize (int size)

Ensures that the array has a given number of elements.

Parameters
size
The desired size of the Array.
Remarks
The expanded region of the Array is filled with undefs.

Pop
public Value Pop ()

Pops the last Value off the end of the Array.

Returns
The Value removed from the end of the Array.

Push
public void Push (Value value)

Pushes a value onto the end of the Array.

Parameters
value
The Value to add to the end of the Array.

Shift
public Value Shift ()

Removes the first item from the array and shifts the array down.

Returns
The Value removed from the start of the Array.

Unshift
public void Unshift (int number)

Shifts the elements of the Array down, making room at the start of the Array.

Parameters
number
The number of places to shift the array down.
Remarks
The new region is filled with undefs.

Unshift
public void Unshift (Value value)

Pushes a Value into the start of the array.

Parameters
value
The value to unshift into the first position of the array.
Remarks
This is the inverse function to Shift.

Unshift
public void Unshift (Value[] values)

Pushes Values into the start of the array.

Parameters
values
The values to unshift into the first positions of the array.
Remarks
This is the inverse function to Shift, repeated several times. The values are unshifted in reverse order, so the first element of values becomes the first element of the array.

Contains
public bool Contains (Value s)

Returns whether the array contains the value.

Parameters
s
The value to be tested whether it is in the array.
Returns
Whether the array contains s.
Remarks
This operation runs in linear time.

IndexOf
public int IndexOf (Value s)

Returns the first index of the value in the array, or -1 if it is not in the array.

Parameters
s
The value to be found in the array.
Returns
The index of s in the array, or -1 if it is not in the array.
Remarks
This operation runs in linear time.

Add
public int Add (object o)

Pushes the object onto the array.

Parameters
o
The object to add. It will be converted to a Value if necessary.
Returns
The index of the object in the array.

AddRange
public void AddRange (ICollection e)

Pushes the elements of a collection onto the array.

Parameters
e
The collection whose elements are to be pushed.
Remarks
The elements are pushed in their order in the collection.

Contains
public bool Contains (object o)

Returns whether the array contains the object.

Parameters
o
The object to be tested whether it is in the array. It is converted to a Value first if necessary.
Returns
Whether the array contains o.
Remarks
This operation runs in linear time.

IndexOf
public int IndexOf (object o)

Returns the first index of the object in the array, or -1 if it is not in the array.

Parameters
o
The object to be found in the array. It is converted to a Value first if necessary.
Returns
The index of o in the array, or -1 if it is not in the array.
Remarks
This operation runs in linear time.

Remove
public void Remove (object o)

Removes the first instance of an object from the array.

Parameters
o
The object to remove. It is converted to a Value first if necessary.
Remarks
This operation runs in linear time.

Count
public int Count { get; }

Returns the number of elements in the array.

Value
The number of elements in the array.

Item
public Value Item [int index] { set; get; }

Returns an element in the array.

Parameters
index
The index of the element.
Value
The element at index, or null if the position contains undef.