Skip to content

Instantly share code, notes, and snippets.

@miguelangelgonzalez
Last active August 29, 2015 14:21
Show Gist options
  • Save miguelangelgonzalez/e7ba9a2fb88dbabb1e78 to your computer and use it in GitHub Desktop.
Save miguelangelgonzalez/e7ba9a2fb88dbabb1e78 to your computer and use it in GitHub Desktop.
NumberExtensions
using System;
using System.Collections.Generic;
namespace Common.Extensions
{
public static class NumberExtensions
{
public static void Times(this int i, Action<int> action)
{
for (var n = 0; n < i; n++) action(n);
}
public static void Times(this int i, Action action)
{
i.Times(x => action());
}
public static IEnumerable<int> To(this int from, int to)
{
if (from <= to)
for (var i = from; i <= to; i++) yield return i;
else
for (var i = from; i >= to; i--) yield return i;
}
public static bool Between(this int num, int left, int right)
{
return num >= left && num <= right;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment