This documentation is archived and is not being maintained.

Arrays Sample: Demonstrates Creating and Using Managed Arrays

Visual Studio .NET 2003

The Arrays sample illustrates the String and Array classes. It shows how to create and access both single-dimensional and multidimensional .NET Framework arrays in C++.

Building and Running the Sample

To build and run Arrays using Visual Studio

  1. In the Visual Studio IDE, load the solution file Arrays.sln.
  2. In Solution Explorer, right-click the Arrays solution.
  3. On the shortcut menu, click Build.
  4. On the Debug menu, click Start.

How the Sample Works

The sample implements a managed class (X) and a value class (V, later used when building the managed arrays). In addition to the classes, four global functions (func1-4) return a variety of managed array types, both single-dimensional and multidimensional.

In the main function of the sample, a five-dimensional array (rX) is declared and initialized. The array elements are then initialized with an integer value and a string literal. Various assertions then test the characteristics of the multidimensional array. Because the sample is compiled as a managed application, all assertions pass successfully.

An array of managed strings (rStr) is then declared and initialized. The array elements are initialized separately with a literal string ("Hello").

Finally, two arrays of value classes (single-dimensional and multidimensional) are declared and initialized. As before, the array elements are then initialized separately.

See Also

Managed Extensions for C++ Samples