Hi how to use foreach loop in managed code c++ using vs2003.
您好如何使用vs2003在托管代码c ++中使用foreach循环。
4 个解决方案
#1
I've never used it, but this MSDN article indicates the general syntax is just:
我从来没有使用它,但这篇MSDN文章表明一般语法只是:
for each(Type t in IEnumerable)
{
}
#2
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)...
更改是Type是一个引用类,所以你使用“Type ^”而不是“Type”,你需要一个实际的对象引用(iterate_me)...
#3
Something like:
String ^ MyString = gcnew String("abcd");
for each ( Char c in MyString )
Console::Write(c);
#4
I don't think that VC++ has foreach
我认为VC ++不具备预期性
#1
I've never used it, but this MSDN article indicates the general syntax is just:
我从来没有使用它,但这篇MSDN文章表明一般语法只是:
for each(Type t in IEnumerable)
{
}
#2
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)...
更改是Type是一个引用类,所以你使用“Type ^”而不是“Type”,你需要一个实际的对象引用(iterate_me)...
#3
Something like:
String ^ MyString = gcnew String("abcd");
for each ( Char c in MyString )
Console::Write(c);
#4
I don't think that VC++ has foreach
我认为VC ++不具备预期性