Int32 - Abs
Returns the absolute value of a 32-bit signed integer.
public static void Main() { Int32[] values = { 15000, 10000, 2500, 1, 7, 30, 365, 1000, -2500, -10000, -15000 }; Console.WriteLine("{0,10}{1,10}","Int32", "Abs"); Console.WriteLine("{0,10}{1,10}","-----", "---"); foreach (Int32 value in values) { // C# Extension Method: Int32 - Abs Console.WriteLine("{0,10}{1,10}", value, value.Abs()); } }
View Source
using System; public static partial class Extensions { /// <summary> /// Returns the absolute value of a 32-bit signed integer. /// </summary> /// <param name="value">A number that is greater than , but less than or equal to .</param> /// <returns>A 32-bit signed integer, x, such that 0 ? x ?.</returns> public static Int32 Abs(this Int32 value) { return Math.Abs(value); } }