experiments/csharp/E024-Foreach/Program.cs

17 lines
335 B
C#
Raw Permalink Normal View History

2024-05-04 20:16:52 +00:00
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;
}
}