Hi how to use foreach loop in managed code c++ using vs2003.
I've never used it, but this MSDN article indicates the general syntax is just:
for each(Type t in IEnumerable)
{
}
Matthew is mostly correct, but here's a working block of code;
///////
array<Type^>^ iterate_me = gcnew array<Type^>(2);
iterate_me[0] = Type::GetType("Type");
iterate_me[1] = Type::GetType("System.Int32");
///////
for each(Type^ t in iterate_me)
Console::WriteLine(t);
The changes were Type is a reference class, so you use "Type^" not "Type" and you need an actual object reference (iterate_me)...
Something like:
String ^ MyString = gcnew String("abcd");
for each ( Char c in MyString )
Console::Write(c);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With