This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1533|Reply: 0

[Source] .NET/C# elegantly sets the int value in the range of the range

[Copy link]
Posted on 11/5/2024 4:43:48 PM | | | |
Requirements: There is a pagination list on the front-end that supports customizing the number of pages displayed, and the interface needs to verify the paging value.

The back-end interface supports the number of displays per page: 1-100, with a minimum return of 1 and a maximum of 100 returns. If the user passes in a value less than 1, you want to reset the value to 1, and if the user passes in a value greater than 100, you want to reset the value to 100.

Original writing:

Not at allNot elegant enoughIs there a better way to implement it? Of course there are, as follows:

Test:



If min ≤ value ≤ max, then value.

-Or-

If value<min, then min.

-Or-

If max<value, it's max.


Reference:The hyperlink login is visible.





Previous:CentOS 7 upgrades to gcc version
Next:The bit weight method converts binary, 8, and hexadecimal into decimal system
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com