Visual C++ .NET/Collections/IEnumerable
Версия от 15:31, 26 мая 2010; (обсуждение)
Cast an array to IEnumerable
#include "stdafx.h"
using namespace System;
using namespace System::Collections;
void main()
{
array<int>^ IntList = gcnew array<int> { 1, 2, 3, 4, 5 };
IEnumerable ^collection = (IEnumerable^)IntList;
IEnumerator ^enumerator = collection->GetEnumerator();
while (enumerator->MoveNext())
{
int i = (int)enumerator->Current;
Console::WriteLine(i);
}
for each (int i in IntList)
Console::WriteLine(i);
}
Get Enumerator from IEnumerable
#include "stdafx.h"
using namespace System;
using namespace System::Collections;
void main()
{
array<int>^ IntList = gcnew array<int> { 1, 2, 3, 4, 5 };
IEnumerable ^collection = (IEnumerable^)IntList;
IEnumerator ^enumerator = collection->GetEnumerator();
while (enumerator->MoveNext())
{
int i = (int)enumerator->Current;
Console::WriteLine(i);
}
for each (int i in IntList)
Console::WriteLine(i);
}