7,540
社区成员
发帖
与我相关
我的任务
分享
// for_each_arrays.cpp
// compile with: /clr
using namespace System;
ref struct MyClass {
void Test() { Console::WriteLine("in MyClass"); }
};
ref struct MyClass2 {
void Test() { Console::WriteLine("in MyClass2"); }
};
int main() {
array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(2);
int i = 0;
for each ( MyClass ^ c in MyArray ) {
Console::Write("{0} = ", i++);
c -> Test();
}
Console::WriteLine();
array< MyClass2 ^, 2 > ^ MyArray2 = gcnew array< MyClass2 ^, 2 >(2, 2);
i = 0;
for each ( MyClass2 ^ c in MyArray2 ) {
Console::Write("{0} = ", i++);
c -> Test();
}
array< MyClass2 ^, 2 > ^ MyArray3 = gcnew array< MyClass2 ^, 2 >(2, 0);
i = 0;
for each ( MyClass2 ^ c in MyArray3 ) {
Console::Write("{0} = ", i++);
c -> Test();
}
}