C# Math Sign(Int16)
Description
Math Sign(Int16)
returns a value indicating the sign
of a 16-bit signed integer.
Syntax
Math.Sign(Int16)
has the following syntax.
public static int Sign(
short value
)
Parameters
Math.Sign(Int16)
has the following parameters.
value
- A signed number.
Returns
Math.Sign(Int16)
method returns A number that indicates the sign of value, as shown in the following table.
Return value Meaning -1 value is less than zero. 0 value is equal to zero. 1
value is greater than zero.
Example
The following example demonstrates how to use the Sign(Int16) method to determine the sign of an Int16 value and display it to the console.
using System;/*w w w . j a v a 2 s . c om*/
class Sample
{
public static void Main()
{
short xShort1 = -2;
Console.WriteLine(Test(Math.Sign(xShort1)));
}
public static String Test(int compare)
{
if (compare == 0)
return "equal to";
else if (compare < 0)
return "less than";
else
return "greater than";
}
}
The code above generates the following result.