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
Type | Name | Signature |
---|---|---|
field C | length | public const int length |
method | at | public var at(var) |
method | at | public void at(var, var) |
method S | copy | public static int copy(Array, int, Array, int, int) |
method S | createArray | public static Array createArray(System.Type, int) |
method S | fill | public static void fill(Array, var) |
method | getElementType | public System.Type getElementType() |
method | getIterator | public System.Util.IIterator getIterator() |
method | size | public int size() |
method S | sort | public static void sort(Array, bool) |
public const int length
The length of this array. Note for multi-dimensional array this refers to the length of the first dimension.
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
Returns
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
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
Returns
Throws
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
Returns
Throws
public static void fill(Array src, var val)
Populate the entire array with a single value.
Parameters
Throws
public Type getElementType()
Get the element type for this array.
Returns
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
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
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