using System;
using System.Collections.Generic;
namespace Articulos.Cap04.Iteradores
{
public sealed class IteradorNumerosEnteros
{
public static void Main()
{
Console.WriteLine ();
foreach (int numero in GeneradorNumerosPares(3, 21))
{
Console.Write ("{0} ", numero.ToString());
}
Console.WriteLine ();
Console.ReadLine ();
}
// Genera números pares a partir de un rango de valores:
private static IEnumerable<int> GeneradorNumerosPares(int inferior, int superior)
{
for (int numero = inferior; numero <= superior; ++numero)
{
// Evalúa si el número es par:
if (numero % 2 == 0)
{
yield return numero;
}
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKCm5hbWVzcGFjZSBBcnRpY3Vsb3MuQ2FwMDQuSXRlcmFkb3Jlcwp7CiAgICBwdWJsaWMgc2VhbGVkIGNsYXNzIEl0ZXJhZG9yTnVtZXJvc0VudGVyb3MKICAgIHsKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCiAgICAgICAgewogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIGZvcmVhY2ggKGludCBudW1lcm8gaW4gR2VuZXJhZG9yTnVtZXJvc1BhcmVzKDMsIDIxKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZSAoInswfSAiLCBudW1lcm8uVG9TdHJpbmcoKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgpOwogICAgICAgICAgICBDb25zb2xlLlJlYWRMaW5lICgpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICAvLyBHZW5lcmEgbsO6bWVyb3MgcGFyZXMgYSBwYXJ0aXIgZGUgdW4gcmFuZ28gZGUgdmFsb3JlczoKICAgICAgICBwcml2YXRlIHN0YXRpYyBJRW51bWVyYWJsZTxpbnQ+IEdlbmVyYWRvck51bWVyb3NQYXJlcyhpbnQgaW5mZXJpb3IsIGludCBzdXBlcmlvcikKICAgICAgICB7CiAgICAgICAgICAgIGZvciAoaW50IG51bWVybyA9IGluZmVyaW9yOyBudW1lcm8gPD0gc3VwZXJpb3I7ICsrbnVtZXJvKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAvLyBFdmFsw7phIHNpIGVsIG7Dum1lcm8gZXMgcGFyOgogICAgICAgICAgICAgICAgaWYgKG51bWVybyAlIDIgPT0gMCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICB5aWVsZCByZXR1cm4gbnVtZXJvOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9