我如何检查一个数字是正的或负的c# ?


当前回答

num < 0 // number is negative

其他回答

你只需要比较是否值和它的绝对值相等:

if (value == Math.abs(value))
    return "Positif"
else return "Negatif"
num < 0 // number is negative

当然没有人给出正确答案,

num != 0   // num is positive *or* negative!

第一个参数存储在EAX寄存器和结果中。

function IsNegative(ANum: Integer): LongBool; assembler;
asm
   and eax, $80000000
end;

你们这些年轻人,还有你们喜欢的"不到"标志。

在我的时代,我们必须使用Math.abs(num) != num //number是负的!