Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int Clamp(int value, int lowerBound, int upperBound)
- {
- if (lowerBound > upperBound)
- {
- throw new ArgumentException("Нижняя граница не может быть больше верхней границы.");
- }
- if (value < lowerBound)
- {
- return lowerBound;
- }
- else if (value > upperBound)
- {
- return upperBound;
- }
- else
- {
- return value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement