System::Collections::Generic::IEnumerator class
IEnumerator class
Interface of enumerator which can be used to iterate through some elements. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.
template<typename T>class IEnumerator : public virtual System::IDisposable,
public System::Details::EnumeratorBasedIterator<T>,
protected System::Details::IteratorPointerUpdater<T, false>
Parameter | Description |
---|
T | Element type. |
Methods
Typedefs
#include <system/collections/list.h>
#include <system/smart_ptr.h>
using namespace System;
using namespace System::Collections::Generic;
int main()
{
// Create the List-class instance.
auto collection = MakeObject<List<int>>();
// Fill the list.
collection->Add(1);
collection->Add(2);
collection->Add(3);
// Get the enumerator of the list.
auto enumerator = collection->GetEnumerator();
while (enumerator->MoveNext())
{
// Get the current element and print it.
std::cout << enumerator->get_Current() << ' ';
}
// Reset the enumerator.
enumerator->Reset();
return 0;
}
/*
This code example produces the following output:
1 2 3
*/
See Also