experiments/csharp/E024-Foreach/Program.cs

17 lines
335 B
C#
Raw Normal View History

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