开发者

C#: How can I make an integer negative?

开发者 https://www.devze.com 2023-01-01 07:47 出处:网络
How can I make an integer negative in C#? abc = 5开发者_JS百科645307; // how to make abc -5645307 ?

How can I make an integer negative in C#?

abc = 5开发者_JS百科645307;
// how to make abc -5645307 ?


Maybe I'm missing something:

abc = -abc;

If you want it to be negative whether it was negative beforehand or not, you would use:

abc = -Math.Abs(abc);


This is how you can convert your int value to minus in c#

abc = abc > 0 ? abc*(-1) : abc;


how about....

xyz = Math.Abs(xyz) * (-1)
0

精彩评论

暂无评论...
验证码 换一张
取 消