dimanche 26 mai 2019

yield return IEnumerator or IEnumerable

I'm new to C#, just a question on yield keyword which confuses me a lot. It seems that yield can return an IEnumerator and IEnumerable

//case 1
static IEnumerator YieldReturn()
{
   yield return 1;
   yield return 2;
   yield return 3;
}

and

//case 2
static IEnumerable YieldReturn()
{
   yield return 1;
   yield return 2;
   yield return 3;
}

how come one thing can return two different return types?

Aucun commentaire:

Enregistrer un commentaire