Пример #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Normal collection");
            foreach (var m in GetMultiplesOf(2, 1, 10))
            {
                Console.WriteLine($"{m} es multiplo de 2");
            }
            Console.WriteLine();

            Console.WriteLine("Yield collection");
            foreach (var m in YieldMultiplesOf(2, 1, 10))
            {
                Console.WriteLine($"{m} es multiplo de 2");
            }
            Console.WriteLine();


            Console.WriteLine("Normal collection");
            foreach (var m in GetMultiplesOf(3, 15, 67))
            {
                if (m == 30)
                {
                    Console.WriteLine($"¡Encontré 30!");
                    break;
                }
            }
            Console.WriteLine();
            Console.WriteLine("Yield collection");
            foreach (var m in YieldMultiplesOf(3, 15, 67))
            {
                if (m == 30)
                {
                    Console.WriteLine($"¡Encontré 30!");
                    break;
                }
            }
            Console.WriteLine();


            var get = GetMultiplesOf(2, 320, 335).Skip(3).First();

            Console.WriteLine($"El cuarto multiplo es {get}");
            Console.WriteLine();
            var yield = YieldMultiplesOf(2, 320, 335).Skip(3).First();

            Console.WriteLine($"El cuarto multiplo es {yield}");


            Console.WriteLine();
            Console.WriteLine("Prime factors of 10080");
            foreach (var factor in PrimeFactors(10080))
            {
                Console.Write(factor + " ");
            }
            Console.WriteLine();


            Console.WriteLine();
            Console.WriteLine("Randoms:");
            var random  = new NotSoRandom();
            var numbers = random.Where(r => r % 3 == 0).Take(10);

            //var numbers = random.Where(r => r % 3 == 0).Take(10).ToList();
            Console.WriteLine("Aún no ocurre nada...");
            foreach (var n in numbers)
            {
                Console.WriteLine(n);
            }

            // WARNING:
            //var allRandoms = random.ToArray();
        }