fork download
  1. using System;
  2. using System.Collections;
  3.  
  4. namespace Articulos.Cap04.Iteardores
  5. {
  6. public sealed class Multiplesyield
  7. {
  8. public static void Main()
  9. {
  10. Console.WriteLine ();
  11.  
  12. // Consumidor del iterador:
  13. foreach (int numero in ListaNumeros())
  14. {
  15. Console.WriteLine ("{0} ", numero.ToString());
  16. }
  17.  
  18. Console.ReadLine ();
  19. }
  20.  
  21. // Método iterador con múltiples sentencias
  22. // yield return:
  23. private static IEnumerable ListaNumeros()
  24. {
  25. yield return 1;
  26. yield return 2;
  27. yield return 3;
  28. }
  29. }
  30. }
Success #stdin #stdout 0.03s 33688KB
stdin
Standard input is empty
stdout
1 
2 
3