%Array
This special method either creates an array object (when applied to a connection object) or returns an attribute mark delimited dynamic array (when applied to a language array object).
%Array works only with arrays of primitive data types, not arrays of objects.
All special method names and keywords are case-insensitive.
Syntax
For connection objects:
{connection->}%Array()
{connection->}%Array(type, array-elements)
{connection->}%Array(type, dyn-array)
For language objects:
object->%Array()
Syntax elements
connectionA connection object. The default connection object does not have to be named (although it can be).
typeA primitive data type.
-
For Java language objects, this is name of the primitive data type itself.
-
For .NET language objects, this is name of the class that wraps the primitive data type.
-
For internal objects, the value of type is ignored, but is still required.
array-elementsA comma-separated list of array elements of the specified type.
dyn-arrayAn expression that evaluates to an attribute mark delimited dynamic array.
objectAn expression that evaluates to a language array object.
Commentsy
Array() produces an empty array, but only when the named or default connection is to an Object Manager; otherwise, it causes a runtime error.
The variant of %Array that returns a dynamic array from an array of primitive data types applies only to Java and .NET language objects.
Note
When %Array() is applied to a Java byte array it returns a string rather than a dynamic array.
When %Array() applied to a .NET System.Byte or System.SByte array object it returns a dynamic array of numeric elements.
Primitive data types
The primitive date types (Java) and wrapper classes (.NET) that are accepted as type values are listed below.
Java primitive type |
.NET class name[1] |
Description |
---|---|---|
char |
System.Char[2] |
2 byte Unicode characters. |
byte |
System.SByte |
Signed 8 bit integer. |
short |
System.Int16 |
Signed 16 bit integer. |
int |
System.Int32 |
Signed 32 bit integer. |
long |
System.Int64 |
Signed 64 bit integer. |
|
System.Byte |
Unsigned 8 bit integer. |
|
System.UInt16 |
Unsigned 16 bit integer. |
|
System.UInt32 |
Unsigned 32 bit integer. |
|
System.UInt64 |
Unsigned 64 bit integer. |
float |
System.Single |
32 bit floating point. |
double |
System.Double |
64 bit floating point. |
|
System.Decimal |
128-bit floating point. |
boolean |
System.Boolean |
Two values – true|false. |
string[3] |
System.String[3] |
Sequence of Unicode characters.[4] |
[1] Currently, the DNLS requires the full wrapper class name. [2] There is no such thing as a signed or unsigned character in C#. [3] String is not a primitive data type in either Java or C# but it is treated as such by the language server. [4] ASCII to Unicode conversion is automatic. |
For internal objects a type must be present but it is ignored because there is no limitation on array elements being the same type. However it is obviously good practice to choose a meaningful value such as int, char, bool, float or string in your DataBasic programs.
Examples
Creates an empty array object. Note that this works only for internal objects.
EmptyArray = ObjMgr->%Array()
Creates a Java language array object from a list of integers.
JavaLS = %Connect(JAVA) FirstTenPrimes = JavaLS->%Array(int, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
Creates a .NET language array object from a list of integers.
DotNetLS = %Connect(DOTNET) FirstTenPrimes = DotNetLS->%Array(System.Int32, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
Creates an internal object from a list of integers.
ObjMgr = %ObjMgr() FirstTenPrimes = ObjMgr->%Array(int, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
Creates the same array object (in this case in Java) but from a dynamic list.
JavaLS = %Connect(JAVA) Primes = "2^3^5^7^11^13^17^19^23^29" Primes = CHANGE(Primes, '^', @AM) FirstTenPrimes = %Array(int, Primes)
Creates a dynamic array from an array object.
JavaLS = %Connect(JAVA) NextTenPrimes = %Array(int, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71) CopiedPrimes = FirstTenPrimes->Array()