I was going through some C# code and came upon this line:
Matrix[i, j] = Convert.ToInt32(grab[i, j] - '0');
What exactly does the ( - ) do??
What would be another way to write this if there is one?
The -
(minus) does exactly what it always does - subtracting. What happens here is subtracting the character code of zero '0'
from the character at [i,j]
. This converts a digit character to an integer value of the corresponding digit. For example, if you calculate
char digitChar = '7';
int digitVal = digitChar - '0';
the value of digitVal
is seven.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With