I am quite new to C# and I want to do an if condition on a number range of a negative value eg if(percentage is equals to -60 to -80 ) then DoWork, my question is , How do I check using an if statement, as switches doesn't allow checks on decimal values. -60 to -80 means (negative 61 up till negative 81) as my condition, how can I achieve this in C#, any help will be greatly appreciated ,like I said I am still new to the .Net world.
if(value >= -80 && value <= -60) {
doWork();
}
I'm guessing when you say 'decimal value ranges' and percentages, you're doing the calculation, so in that case:
if( x >= -.81 && x <= -.61) { //do something }
otherwise, it would be:
if( x >= -81 && x <= -61) { //do something }
if(number >= -80.0f && number <= -60.0f)
{
// Do stuff
}
if(a >= -80 && a <= -60) {
DoWork();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.