Last active
August 29, 2015 14:21
-
-
Save miguelangelgonzalez/e7ba9a2fb88dbabb1e78 to your computer and use it in GitHub Desktop.
NumberExtensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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