共用方式為


How to: Create an Array of Arrays 

An array with arrays for elements is called an array of arrays, or a jagged array. As with a one-dimensional array, you create it with a New (Visual Basic) clause and assign it to the array variable. You can do this as part of the array declaration, or in a subsequent assignment statement.

To create a jagged array

  1. Add as many pairs of parentheses after the variable name as there are levels of nested arrays.

  2. Add the same number of pairs of parentheses to the New clause. You do not need more than one pair of braces ({}) if you are not supplying any element values. The following example declares a variable to hold an array of arrays with elements of the Byte Data Type (Visual Basic), creates the array, and assigns it to the variable.

    Dim ratings As Byte()() = New Byte()() {}
    

    Following the execution of this statement, the array in variable ratings has length 0.

    Note

    Jagged arrays are not compliant with the Common Language Specification (CLS). This means you should not expose jagged arrays from any class you want CLS-compliant code to use.

See Also

Tasks

How to: Declare an Array Variable
How to: Create an Array
How to: Create an Array with More Than One Dimension
How to: Create an Array with Mixed Element Types
How to: Create an Array with No Elements
How to: Initialize a Jagged Array
Troubleshooting Arrays

Concepts

Jagged Arrays in Visual Basic
Writing CLS-Compliant Code

Other Resources

Arrays in Visual Basic