NET.createArray

Package: NET

Array for nonprimitive .NET types

Syntax

array = NET.createArray(typeName,[m,n,p,...])
array = NET.createArray(typeName,m,n,p,...)

Description

array = NET.createArray(typeName,[m,n,p,...]) creates an m-by-n-by-p-by-... array of type typeName, which is either a fully qualified .NET array type name (namespace and array type name) or an instance of the NET.GenericClass class, in case of arrays of generic type. m,n,p,... are the number of elements in each dimension of the array.

array = NET.createArray(typeName,m,n,p,...) alternative syntax for creating an array.

You cannot specify the lower bound of an array.

Examples

Create .NET Array of Generic Type

This example creates a .NET array of List<Int32> generic type.

genType = NET.GenericClass('System.Collections.Generic.List',...
  'System.Int32'); 
arr = NET.createArray(genType, 5)
arr = 

  List<System*Int32>[] with properties: 

            Length: 5 
        LongLength: 5 
              Rank: 1 
          SyncRoot: [1x1 System.Collections.Generic.List<System*Int32>[]] 
        IsReadOnly: 0 
       IsFixedSize: 1 
    IsSynchronized: 0 

Create and Initialize Jagged Array

This example creates a jagged .NET array of 3 elements.

jaggedArray = NET.createArray('System.Double[]', 3)
jaggedArray = 

  Double[][] with properties

            Length: 3
        LongLength: 3
              Rank: 1
          SyncRoot: [1x1 System.Double[][]]
        IsReadOnly: 0
       IsFixedSize: 1
    IsSynchronized: 0

Assign values:

jaggedArray(1) = [1, 3, 5, 7, 9];
jaggedArray(2) = [0, 2, 4, 6];
jaggedArray(3) = [11, 22];

Access first value of 3rd array:

jaggedArray(3,1)
ans =
    11

Create Jagged Array of Generic Type

This example creates a jagged array of List<Double> generic type.

genCls = NET.GenericClass('System.Collections.Generic.List[]',...
  'System.Double');

Create the array, genArr.

genArr = NET.createArray(genCls,3)
genArr = 

  List<System*Double>[][] with properties:

            Length: 3
        LongLength: 3
              Rank: 1
          SyncRoot: [1x1 System.Collections.Generic.List`1[][]]
        IsReadOnly: 0
       IsFixedSize: 1
    IsSynchronized: 0

Create Nested Jagged Array

This command creates a jagged array of type System.Double[][][].

netArr = NET.createArray('System.Double[][]', 3)
netArr = 

  Double[][][] with properties:

            Length: 3
        LongLength: 3
              Rank: 1
          SyncRoot: [1x1 System.Double[][][]]
        IsReadOnly: 0
       IsFixedSize: 1
    IsSynchronized: 0
Was this topic helpful?