C #: How can I make an integer negative?

How can I make an integer negative in C #?

abc = 5645307; // how to make abc -5645307 ? 
+4
source share
3 answers

Maybe I missed something:

 abc = -abc; 

If you want it to be negative, whether it was negative in advance or not, you should use:

 abc = -Math.Abs(abc); 
+43
source

Here is how you can convert your value to minus value in C #

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

What about....

 xyz = Math.Abs(xyz) * (-1) 
+1
source

Source: https://habr.com/ru/post/1310731/


All Articles