Skip to content

Instantly share code, notes, and snippets.

@MovGP0
Created February 27, 2017 15:53
Show Gist options
  • Save MovGP0/ff909a0baf2e188da57e6ea9411e9eec to your computer and use it in GitHub Desktop.
Save MovGP0/ff909a0baf2e188da57e6ea9411e9eec to your computer and use it in GitHub Desktop.
Common extension methods
public static class IntegerExtensions
{
///<summary>Returns an enumerable range of integers</summary>
///<example><c>5.To(9)</c></example>
///<example><c>5.To(-3)</c></example>
public static IEnumerable<int> To(this int start,int end)
{
var sign = Math.Sign(end - start);
while(start != end)
{
yield return start;
start += sign;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment