Facebook Page Twitter Page LinkedIn Page
× C# Tutorial C# Advanced C# Resources


The C# Math Sign() method is used to return an integer that indicates the sign of the argument. It returns zero if the argument is zero, 1 if the argument is greater than zero, -1 if the argument is less than zero. The method can be overloaded and it can take float, sbyte, int, long, double, decimal and short arguments.

Syntax

public static int Sign (float value);
public static int Sign (sbyte value);
public static int Sign (int value);
public static int Sign (long value);
public static int Sign (double value);
public static int Sign (decimal value);
public static int Sign (short value);

Parameters

value Specify a signed value.

Return Value

Returns an integer that indicates the sign of the argument.

Exception

throws ArithmeticException, if the argument is NaN.

Example:

In the below example, Sign() method is used to return an integer that indicates the sign of the argument.

using System;

class MyProgram {
  static void Main(string[] args) {
	Console.WriteLine(Math.Sign(48.45));   
	Console.WriteLine(Math.Sign(-48.667));  
	Console.WriteLine(Math.Sign(0));  
  }
}

The output of the above code will be:

1
-1
0

❮ C# Math Methods