C# Math Abs(Int16)
Description
Math Abs(Int16)
returns the absolute value of a 16-bit
signed integer.
Syntax
Math.Abs(Int16)
has the following syntax.
public static short Abs(
short value
)
Parameters
Math.Abs(Int16)
has the following parameters.
value
- A number that is greater than Int16.MinValue, but less than or equal to Int16.MaxValue.
Returns
Math.Abs(Int16)
method returns A 16-bit signed integer, x, such that 0 d x d Int16.MaxValue.
Example
The following example uses the Abs(Int16) method to get the absolute value of a number of Int16 values.
// w w w . jav a 2 s.co m
using System;
public class Example
{
public static void Main()
{
short[] values = { Int16.MaxValue, 12345, 0, -1234, Int16.MinValue };
foreach (short value in values)
{
try {
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
}
catch (OverflowException) {
Console.WriteLine("Unable to calculate the absolute value of {0}.",
value);
}
}
}
}
The code above generates the following result.