Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Yield Statement
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Divers
Thread ID:
01462394
Message ID:
01462402
Vues:
60
I think this is explained a little better here http://msdn.microsoft.com/en-us/library/65zzykke.aspx, specially if you look at the middle example.

You can use more than one yield statement in the same iterator as in the following example:
public System.Collections.IEnumerator GetEnumerator()
{
    yield return "With an iterator, ";
    yield return "more than one ";
    yield return "value can be returned";
    yield return ".";
}
You can then print the results using the following foreach statement:
foreach (string element in new TestClass())
{
    System.Console.Write(element);
}
// Output: With an iterator, more than one value can be returned.
This example displays the following text:

With an iterator, more than one value can be returned.

On each successive iteration of the foreach loop (or the direct call to IEnumerator.MoveNext), the next iterator code body
resumes after the previous yield statement and continues to the next until the end of the iterator body is reached,
or a yield break statement is encountered.

Iterators do not support the IEnumerator.Reset method. To re-iterate from the beginning, you must obtain a new iterator.
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform