-
-
Save zyowo/4cf443feef52ffd67520a9a48460eaf7 to your computer and use it in GitHub Desktop.
Gist 就是分享代码段的地方?
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
/// <summary> | |
/// [范围限定] 将数字限定在 最小 ~ 最大之间 | |
/// </summary> | |
/// <param name="value">限定数字</param> | |
/// <param name="min">最小值</param> | |
/// <param name="max">最大值</param> | |
/// <returns>限定后结果</returns> | |
public static int Clamp(int value, int min, int max) | |
{ | |
if (max < min) return value; | |
if (value < min) value = min; | |
if (value > max) value = max; | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment