Main Content

NET.createArray

Array for nonprimitive .NET types

Description

example

array = NET.createArray(typeName,[m,n,p,...]) creates a multidimensional .NET array of type typeName.

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

You cannot specify the lower bound of an array.

Examples

collapse all

Create 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 a .NET array of three 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 to arrays of different dimensions.

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

Display the first value of the third array.

jaggedArray(3,1)
ans =
    11

Create a jagged array of List<Double> generic type.

Define the generic type.

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

Create the array.

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

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

            Length: 3
        LongLength: 3
              Rank: 1
          SyncRoot: [1×1 System.Collections.Generic.List<System*Double>[][]]
        IsReadOnly: 0
       IsFixedSize: 1
    IsSynchronized: 0

Create 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

Input Arguments

collapse all

Fully specified .NET array type name, specified as a string, character vector, or NET.GenericClass object.

Example: 'System.Double[]'

Example: 'NET.GenericClass('System.Collections.Generic.List','System.Int32')'

Number of elements in each dimension, specified as an array of integers.

Introduced in R2009a