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.
The function returns an integer that indicates the sign of param
.
Sign (type param);
where:
value
: is a signed number0
: Returns this if param = 0
1
: Returns this if param > 0
-1
: Returns this if param < 0
public static int Sign (float param);
public static int Sign (sbyte param);
public static int Sign (long param);
public static int Sign (decimal param);
public static int Sign (short param);
public static int Sign (double param);
public static int Sign (int param);
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));}}