Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在浏览一些 C# 代码并遇到了这一行:
Matrix[i, j] = Convert.ToInt32(grab[i, j] - '0');
( - ) 究竟是做什么的?
如果有的话,另一种写法是什么?
-(减号)与它一直做的完全一样——减法。这里发生的是从字符中减去零字符'0'代码[i,j]。这会将数字字符转换为相应数字的整数值。例如,如果您计算
-
'0'
[i,j]
char digitChar = '7'; int digitVal = digitChar - '0';
的值为digitVal七。
digitVal