System::Collections::Generic::IEnumerator class
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
*/
参照