Created
February 27, 2017 15:53
-
-
Save MovGP0/ff909a0baf2e188da57e6ea9411e9eec to your computer and use it in GitHub Desktop.
Common extension methods
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
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