array (Visual C++)
The array keyword lets you create a dynamic array that is allocated on the common language runtime heap.
[qualifiers] [cli::]array<[qualifiers]type1[, dimension]>^var = gcnew [cli::]array<type2[, dimension]>(val[,val...])
The number of elements of the array is not part of the type. A single array variable can refer to arrays of different sizes.
Like standard C++, the indices of a managed array are zero-based, and a managed array is subscripted using ordinary C++ array brackets. Unlike standard C++, subscripting is not a synonym for pointer arithmetic and is not commutative.
A managed array is itself a managed object. It is actually a pointer into the common language runtime heap. As a managed object, it has the same restrictions as a managed class. Most notably, the element type cannot be a native C++ class that is not a POD type.
array is in the cli namespace. See cli Namespace for more information.
All managed arrays inherit from System::Array. Any method or property of System::Array can be applied directly to the array variable.
When allocating an array whose element type is pointer-to a managed class, the elements are 0-initialized.
When allocating an array whose element type is a value type V, the default constructor for V is applied to each array element. For more information, see .NET Framework Equivalents to C++ Native Types.
You can detect at compile time if a type is a CLR array with __is_ref_array(type). For more information, see Compiler Support for Type Traits.
For more information on arrays, see
// clr_array.cpp
// compile with: /clr
ref class MyClass {};
int main() {
// one-dimensional array
array<MyClass ^> ^ My1DArray = gcnew array<MyClass ^>(100);
My1DArray[99] = gcnew MyClass();
// three-dimensional array
array<MyClass ^, 3> ^ My3DArray = gcnew array<MyClass ^, 3>(3, 5, 6);
My3DArray[0,0,0] = gcnew MyClass();
}