Created
August 6, 2020 12:52
-
-
Save asizikov/8506baa39d5a5f66ab31530c79fd3477 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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