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# 中将 2 个正数相加,如果溢出不是应该导致异常的条件,那么检查整数溢出的最佳方法是什么?
我可以检查结果是否为负那么它是溢出吗?
如果溢出正常,您可以检查是否为负数,但这并不能说明足够大的溢出。如果它溢出到足以再次变为正数,那么检查负数显然是行不通的。
但是对于两个正整数,检查负数就可以了。