C# Math Sign(Int64)

Description

Math Sign(Int64) returns a value indicating the sign of a 64-bit signed integer.

Syntax

Math.Sign(Int64) has the following syntax.


public static int Sign(
  long value
)

Parameters

Math.Sign(Int64) has the following parameters.

  • value - A signed number.

Returns

Math.Sign(Int64) 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(Int64) method to determine the sign of an Int64 value and display it to the console.


using System;//from   ww w. j  a  va  2  s. co m

class Sample 
{
    public static void Main() 
    {
        long     xLong1    = -4;
    
        Console.WriteLine(Test(Math.Sign(xLong1)));
    }
    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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version