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