Array CLASS

Array is an indexable vector structure with direct language support. It inherits from Object, and is instantiated using new expression with a special grammar.

To declare an array of one or two dimentions,

int[] ia;
string[][] saa;


The [] grammar can be expanded to any degree.

To intialize an array, there are two ways. First an all-empty array can be initialized by specifying lengths at each dimension in a new expression,

int[] ia = new int[3];
string[][] saa = new string[2][10];


Alternatively, an array initializer can be used to specify values at each index. While Julian does support jagged arrays, length inconsistency is disallowed when using an initializer. If the lengths at the same dimension are not aligned, it would incur a runtime exception.

int[] ia = new int[]{10, 20};
string[][] saa = new string[][]{new string[]{"a", "b"}, new string[]{"c", "d"}};
string[][] saa = new string[][]{new string[]{"a", "b"}, new string[]{"c"}};
// If you want to create jagged array, do something like this
string[][] saa = new string[2][0];
saa[0] = new string[3];
saa[1] = new string[4];


Note, however, that these two syntaxes cannot be mixed in any fashion.

To access an element on an array, use '[]' syntax, a.k.a. indexer:

int i = ia[2];
ia[f()+3] = g();


Array is iteratible. This means one can use foreach grammar on an array.

for(int i : ia) {
  ...
}


Array's length is immutable and fixed during initialization. To use a scalable structure consider List.

For more detailed description on Array, see Julian Tutorial.

Parent Class

Parent Interfaces

All Members


TypeNameSignature
field Clengthpublic const int length
methodatpublic var at(var)
methodatpublic void at(var, var)
method Scopypublic static int copy(Array, int, Array, int, int)
method ScreateArraypublic static Array createArray(System.Type, int)
method Sfillpublic static void fill(Array, var)
methodgetElementTypepublic System.Type getElementType()
methodgetIteratorpublic System.Util.IIterator getIterator()
methodsizepublic int size()
method Ssortpublic static void sort(Array, bool)

Fields


public const int length

The length of this array. Note for multi-dimensional array this refers to the length of the first dimension.


Methods


public var at(var index)

Get the element at specified index.

This is the implementation of getter method on System.Util.IIndexble. Normally an array is accessed by indexer syntax [], but the method-based access can prove useful in certain cases such as reflection.

Parameters

  • index An index at which the element is to be retrieved.

Returns

  • The value retrieved.

Throws


public void at(var index, var value)

Set the element at specified index.

This is the implementation of setter method on System.Util.IIndexble. Normally an array is accessed by indexer syntax [], but the method-based access can prove useful in certain cases such as reflection.

Parameters

  • index An index at which the given value is to be set.
  • value The value to set.

Throws


public static int copy(Array src, int srcOffset, Array dst, int dstOffset, int count)

Copy certain section of one array to that of another.

Parameters

  • src The source array.
  • srcOffset The offset at source array to start copy from. 0-based.
  • dst The target array.
  • dstOffset The offset at target array to start copy to. 0-based.
  • count The total length to copy over.

Returns

Throws

  • System.Lang.RuntimeCheckException if the parameters are not meeting the requirements, such astype being incompatible, values overlapping, illegal values or illegal combination thereof, of parametrers, etc.

public static Array createArray(Type elementType, int length)

Create a new array of the specifed element type and length. This is equivalent to new T[].

Parameters

  • elementType The element type (T).
  • length The array's length (N)

Returns

  • An N-sized array object of type T[].

Throws


public static void fill(Array src, var val)

Populate the entire array with a single value.

Parameters

  • src The array to populate.
  • val The value used to fill out each element.

Throws


public Type getElementType()

Get the element type for this array.

Returns

  • A System.Type object representing the element type of the array.

public IIterator getIterator()

Get an iterator from this array.

This is the implementation of System.Util.IIterable. To boost efficiency, applying 'fast-for' loop over an array will not actually use an iterator produced from this method. To explicitly use this iterator one must call getIterator() on an array to get the iterator object.

Returns

  • An array iterator ready to move on.

public int size()

Get the size of the array.

This is the implementation of size() method on System.Util.IIndexble. This is equivalent to length field.

Returns

  • The length of this array.

public static void sort(Array src, bool desc)

Sort the given array.

To sort an array, it requires that the elements be able to compare to each other. Certain primitive types and built-in types are comparable to some others. For example, int, float and bytes types are mutually comparable. However, the user-defined types are not naturally comparable. To add comparability to these types, one must implement System.Util.IComparable.

The sorting process is tolerant of incomparability, but the result will not be even partially correct if any pair of elements is found to be incomparable to each other.

This method is to sort the given array in place. In particular, it's not thread safe and therefore must be protected by locks.

Parameters

  • src The array to sort in place.
  • desc If false, sort in ascendingly order; if true, in descending order.