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:
Yield Statement
Divers
Thread ID:
01462394
Message ID:
01462394
Vues:
121
I was looking at this:
http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx

Which seems to do the same as this:
List<int> Values = GetPowers(2, 8);
foreach (int i in Values)
{
    Console.Write("{0} ", i);
}


public static List<int> GetPowers(int number, int exponent)
{
    List<int> RetVal = new List<int>();

    int counter = 0;
    int result = 1;
    while (counter++ < exponent)
    {
        result = result * number;
        RetVal.Add(result);
    }

    return RetVal;
}
The yield statement calls into the Power methid repeatedly. This seems rather confusing to me, as apposed to my code above that
gets and returns all the values at once, the processes them.

I'd like to know what others think.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform