ManagedArray.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:2k
- // This is the main project file for VC++ application project
- // generated using an Application Wizard.
- #include "stdafx.h"
- #using <mscorlib.dll>
- using namespace System;
- // This is the entry point for this application
- #ifdef _UNICODE
- int wmain(void)
- #else
- int main(void)
- #endif
- {
- // Declare loop counters
- int i,j,k;
- // Create a multidimensional array of Int32
- Int32 pn[,] = new Int32[3,2];
- Console::WriteLine("Rank is {0}", __box(pn->Rank));
- Console::WriteLine("Length is {0}", __box(pn->get_Length()));
- // Print out the array dimension information
- for (i=0; i<pn->get_Rank(); i++)
- Console::WriteLine("Dimension {0} is of size {1}", __box(i),
- __box(pn->GetLength(i)));
- // Fill the array with values
- for (j=0; j<pn->GetLength(0); j++)
- for (k=0; k<pn->GetLength(1); k++)
- pn[j,k] = (j+1)*(k+1);
- // Put '10' in array element [1,1]
- pn->SetValue(__box(10), 1, 1);
- // Print out the array data
- for (j=pn->GetLowerBound(0); j <= pn->GetUpperBound(0); j++)
- for (k=pn->GetLowerBound(1); k <= pn->GetUpperBound(1); k++)
- Console::WriteLine("pn[{0},{1}] = {2}", __box(j),
- __box(k), pn->GetValue(j, k));
- // Create another multidimensional array of Int32
- Int32 pn2[,] = new Int32[3,2];
- // Fill the array with a constant value
- for (j=0; j<pn2->GetLength(0); j++)
- for (k=0; k<pn2->GetLength(1); k++)
- pn2[j,k] = 47;
- // Copy two values from pn to pn2
- System::Array::Copy(pn, 0, pn2, 2, 2);
- // Print out the array data
- Console::WriteLine();
- for (j=pn2->GetLowerBound(0); j <= pn2->GetUpperBound(0); j++)
- for (k=pn2->GetLowerBound(1); k <= pn2->GetUpperBound(1); k++)
- Console::WriteLine("pn2[{0},{1}] = {2}", __box(j),
- __box(k), pn2->GetValue(j, k));
- return 0;
- }