在C#中,可以通过以下方法来取得一个数的绝对值:
int num = -5;
int absNum = Math.Abs(num);
Console.WriteLine(absNum); // 输出:5
int num = -5;
int absNum = num < 0 ? -num : num;
Console.WriteLine(absNum); // 输出:5
int num = -5;
int absNum = (num ^ (num >> 31)) - (num >> 31);
Console.WriteLine(absNum); // 输出:5