Advertisement
Fhernd

Multiplesyield.cs

Aug 18th, 2014
2,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement