C# Math Abs(SByte)
Description
Math Abs(SByte)
returns the absolute value of an 8-bit
signed integer.
Syntax
Math.Abs(SByte)
has the following syntax.
[CLSCompliantAttribute(false)]
public static sbyte Abs(
sbyte value
)
Parameters
Math.Abs(SByte)
has the following parameters.
value
- A number that is greater than SByte.MinValue, but less than or equal to SByte.MaxValue.
Returns
Math.Abs(SByte)
method returns An 8-bit signed integer, x, such that 0 d x d SByte.MaxValue.
Example
The following example uses the Abs(SByte) method to get the absolute value of a number of SByte values.
//from ww w. jav a 2s . c om
using System;
public class Example
{
public static void Main()
{
sbyte[] values = { SByte.MaxValue, 97, 0, -32, SByte.MinValue };
foreach (sbyte 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.