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
{
static void Main()
{
For (10, To: 5)
(
Console.WriteLine
);
}
public static Action<Action<int>> For(int from, int? To = null) =>
x =>
{
if (!To.HasValue) throw new ArgumentNullException(nameof(To));
else if (from > To) for (int i = from; i >= To; i--) x(i);
else for (int i = from; i <= To; i++) x(i);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment