Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#
math
sign
communitycreator

What is Math.Sign() in C#?

Arslan Bajwa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

C# has a built-in Math class that provides useful mathematical functions and operations. The class has the Sign() function, which is used to return the integer indicating the sign of a specified number.

Syntax

The function returns an integer that indicates the sign of param.

Sign (type param);

where:

  • value: is a signed number

Return value

  • 0: Returns this if param = 0

    or

  • 1: Returns this if param > 0

    or

  • -1: Returns this if param < 0

Variants

Sign(Single)

  public static int Sign (float param);

Sign(Sbyte)

  public static int Sign (sbyte param);

Sign(Int64)

  public static int Sign (long param);

Sign(Decimal)

  public static int Sign (decimal param);

Sign(Int16)

  public static int Sign (short param);

Sign(Double)

  public static int Sign (double param);

Sign(Int32)

 public static int Sign (int param);

Examples

using System;
class HelloWorld
{
static void Main()
{
System.Console.WriteLine(Math.Sign(2));
System.Console.WriteLine(Math.Sign(-10.2563M));
System.Console.WriteLine(Math.Sign(0));
}
}

RELATED TAGS

c#
math
sign
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring