왜 모듈러스 연산자 (%)의 결과가 C#의 오른쪽이 아닌 왼쪽으로 내재적으로 변환되는 이유는 무엇입니까?
다음 코드를 취하십시오.long longInteger = 42;
int normalInteger = 23;
object rem = longInteger % normalInteger;
rem
이 longInteger/normalInteger
의 나머지이면, 나머지는 항상 작은 크기의 "int"즉 제수로 한정되어서는 안됩니까? 그러나 C#에서는 위의 코드 결과가 rem
이 long
가됩니다.
데이터 손실없이 rem
을 int
로 변환하는 것이 안전합니까?
int remainder = Convert.ToInt32(rem);
연산자 이름이 "모듈러스"에서 "모듈로"로 편집되었습니다. modulo가 올바른 이름 인 것처럼 보이지만 http://en.wikipedia.org/wiki/Modulo_operation 그러나 MSDN에는 "modulus"가 있습니다 http://msdn.microsoft.com/en-us/library/0w4e0fzs.aspx MSDN이 잘못되었을 수 있다고 생각합니까? – jasonsirota