Skip to content

Instantly share code, notes, and snippets.

@CallumWatkins
Last active February 18, 2017 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CallumWatkins/44e45504db81e1ee9700a2f920bbfa98 to your computer and use it in GitHub Desktop.
Save CallumWatkins/44e45504db81e1ee9700a2f920bbfa98 to your computer and use it in GitHub Desktop.
Checks whether any given integer is located in the range between two other integers. License: MIT
/// <summary>
/// Checks whether any given integer is located in the range between two other integers.
/// </summary>
/// <param name="i">The integer to check.</param>
/// <param name="min">The minimum value of the range.</param>
/// <param name="max">The maximum value of the range.</param>
/// <param name="inclusive">Whether or not the minumum and maximum values are included in the range.</param>
/// <returns>Boolean</returns>
private static bool IsInIntegerRange(this int i, int min, int max, bool inclusive = true)
{
if (inclusive) return i >= min && i <= max;
return i > min && i < max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment