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は 7 です。
digitVal