Skip to content

Instantly share code, notes, and snippets.

@ZacharyPatten
Last active March 9, 2020 12:25
Show Gist options
  • Select an option

  • Save ZacharyPatten/c6e46acd39d3e1d1d19e8da9a482d303 to your computer and use it in GitHub Desktop.

Select an option

Save ZacharyPatten/c6e46acd39d3e1d1d19e8da9a482d303 to your computer and use it in GitHub Desktop.
An example of custom For syntax... Pretty dumb... Just messing around...
using System;
namespace Example
{
class Program
{
static void Main()
{
For (10..5)
(
Console.WriteLine
);
For (5..10, Console.WriteLine);
}
public static Action<Action<int>> For(Range range) =>
x =>
{
int a = range.Start.Value;
int b = range.End.Value;
if (a > b) for (int i = a; i >= b; i--) x(i);
else for (int i = a; i <= b; i++) x(i);
};
public static void For(Range range, Action<int> action)
{
int a = range.Start.Value;
int b = range.End.Value;
if (a > b) for (int i = a; i >= b; i--) action(i);
else for (int i = a; i <= b; i++) action(i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment