Skip to content

Instantly share code, notes, and snippets.

@asizikov
Created August 6, 2020 12:52
Show Gist options
  • Save asizikov/8506baa39d5a5f66ab31530c79fd3477 to your computer and use it in GitHub Desktop.
Save asizikov/8506baa39d5a5f66ab31530c79fd3477 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var source = new Source(new int[] {2,4,5});
foreach (var num in source)
{
Console.WriteLine(num);
Thread.Sleep(1000);
}
}
}
public class Source : IEnumerable<int>
{
private readonly int[] _ints;
public Source(int[] ints)
{
_ints = ints;
}
public IEnumerator<int> GetEnumerator()
{
var rnd = new Random();
while (true)
{
yield return _ints[rnd.Next(_ints.Length)];
}
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment