What is the c# equivalent of iterator in Java
•
Java
I manually convert java to c# and have the following code:
for (Iterator<SGroup> theSGroupIterator = SGroup.getSGroupIterator();
theSGroupIterator.hasNext();)
{
SGroup nextSGroup = theSGroupIterator.next();
}
Is there an equivalent iterator? Is there a better c# idiom in c#?
Solution
The direct equivalent value in C # is ienumerator < T >, and the code is as follows:
SGroup nextSGroup;
using(IEnumerator<SGroup> enumerator = SGroup.GetSGroupEnumerator())
{
while(enumerator.MoveNext())
{
nextSGroup = enumerator.Current;
}
}
But the usual way is:
foreach(SGroup group in SGroup.GetSGroupIterator())
{
...
}
And getsgroupiterator returns a @ L_ 403_ 2 @ (and may be renamed getsgroups() or similar)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
