+ 2
What is a practical application for modulus?
6 Antworten
+ 2
I've used this in the past to detect even vs odd numbers by doing number % 2 if the result is 0 even, otherwise odd
+ 1
In one of my MVC Web applications I use it to determine creation of a new row/column sequence. In this scenario you can say if the number of columns x is evenly divisible by max columns in a row y then create new row. In the example given in the solo learn c# tutorial it is effectively being used to determine a boolean value and return a result if true else return a different value.
0
it can for instance be used to bound a value instead of using if statements.
0
@Bernhard Eriksson sorry I'm new to this and have no idea what that means haha
0
@Ian Jones brilliant, thank you
0
@Connar instead of using if statements to set a max value you can use modulus which is faster than doing if.