Skip to content

Instantly share code, notes, and snippets.

@Atulin
Created December 5, 2020 18:45
Show Gist options
  • Save Atulin/19a16c7b6f4f1e7f19cd9285670e2dde to your computer and use it in GitHub Desktop.
Save Atulin/19a16c7b6f4f1e7f19cd9285670e2dde to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
public static class VonNeumannExtensions
{
public static IEnumerator<int> GetEnumerator(this int number)
{
for (var i = 0; i < number; i++)
{
yield return i;
}
}
public static IEnumerator<int> GetEnumerator(this Range range)
{
for (var i = range.Start.Value; i < range.End.Value; i++)
{
yield return i;
}
}
}
public static class Program {
public static void Main() {
foreach (var i in 3..7) {
Console.WriteLine(i);
}
Console.WriteLine("---");
foreach (var i in 7) {
Console.WriteLine(i);
}
}
}
3
4
5
6
---
0
1
2
3
4
5
6
{
"version": 1,
"target": "Run",
"mode": "Release",
"branch": "master"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment