Skip to content

Commit

Permalink
添加针对int的LimitRange扩展方法
Browse files Browse the repository at this point in the history
  • Loading branch information
iccfish committed Dec 4, 2015
1 parent 94f8411 commit 47ce514
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/FishValueExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public static class FishValueExtension
/// <returns></returns>
public static bool IsValueInRange(this int value, int minValue, int maxValue) { return value >= minValue && value <= maxValue; }

/// <summary>
/// 对数值进行上下限判定,返回限制范围内的数据
/// </summary>
/// <param name="value">当前值</param>
/// <param name="min">最小值。如果 <paramref name="value"/> 小于此值, 则会返回最小值</param>
/// <param name="max">最大值。如果 <paramref name="value"/> 大于此值, 则会返回最大值</param>
/// <returns></returns>
public static int LimitRange(this int value, int min, int max)
{
return value < min ? min : value > max ? max : value;
}

/// <summary>
/// 返回大于等于数字被指定值除的商的数字
/// </summary>
Expand Down

0 comments on commit 47ce514

Please sign in to comment.