Infinite generator C#
From the above python exercise here now a C# flavored version
Code
private static IEnumerable<int> InfiniteGenerator(string input)
{
var index = 0;
var letters = input.ToCharArray();
while (true)
{
yield return letters[index % letters.Length];
index++;
}
}
static public void Main()
{
var value = 0;
foreach (var current in InfiniteGenerator("Close"))
{
value += current;
Console.WriteLine(value);
}
}
Results
67
175
286
401
502
569
677
788
903
1004
1071
1179