experiments/csharp/E024-Foreach/Program.cs

17 lines
335 B
C#

foreach (int i in new CountTo(10))
{
Console.WriteLine(i);
}
public readonly struct CountTo(int max)
{
public CountToEnumerator GetEnumerator() => new(max);
public struct CountToEnumerator(int max)
{
public int Current { get; private set; } = 0;
public bool MoveNext() => Current++ < max;
}
}