Advertisement
VodVas

CleanCode_ExampleTask1.cs

Dec 18th, 2024 (edited)
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | Software | 0 0
  1. public static int Clamp(int value, int lowerBound, int upperBound)
  2. {
  3.     if (lowerBound > upperBound)
  4.     {
  5.         throw new ArgumentException("Нижняя граница не может быть больше верхней границы.");
  6.     }
  7.  
  8.     if (value < lowerBound)
  9.     {
  10.         return lowerBound;
  11.     }
  12.     else if (value > upperBound)
  13.     {
  14.         return upperBound;
  15.     }
  16.     else
  17.     {
  18.         return value;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement