System::Collections::Generic::IEnumerator 类
IEnumerator class
可用于遍历某些元素的枚举器接口。此类的对象只能使用 System::MakeObject() 函数分配。切勿在栈上或使用 operator new 创建此类型的实例,因为这会导致运行时错误和/或断言故障。始终将此类包装到 System::SmartPtr 指针中,并使用该指针将其作为参数传递给函数。
template<typename T>class IEnumerator : public virtual System::IDisposable,
public System::Details::EnumeratorBasedIterator<T>,
protected System::Details::IteratorPointerUpdater<T, false>
方法
Typedefs
备注
#include <system/collections/list.h>
#include <system/smart_ptr.h>
using namespace System;
using namespace System::Collections::Generic;
int main()
{
// 创建 List 类实例。
auto collection = MakeObject<List<int>>();
// 填充列表。
collection->Add(1);
collection->Add(2);
collection->Add(3);
// 获取列表的枚举器。
auto enumerator = collection->GetEnumerator();
while (enumerator->MoveNext())
{
// 获取当前元素并打印。
std::cout << enumerator->get_Current() << ' ';
}
// 重置枚举器。
enumerator->Reset();
return 0;
}
/*
This code example produces the following output:
1 2 3
*/
另见