
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
MathF.Sign() Method in C# with Examples
The MathF.Sign() method in C# returns an integer specifying the sign of the number.
Syntax
Following is the syntax −
public static int Sign (float val);
Above, Val is the floating-point number whose sign is to be calculated.
The return value is 0 if Val is zero. It’s -1 if the value is less than zero and 1 if the value is greater than zero.
Example
Let us now see an example to implement the MathF.Sign() method −
using System; public class Demo { public static void Main(){ float val1 = 10.23898f; float val2 = -20.878788f; Console.WriteLine("MathF.Sign(val1) = "+MathF.Sign(val1)); Console.WriteLine("MathF.Sign(val2) = "+MathF.Sign(val2)); } }
Output
This will produce the following output −
MathF.Sign(val1) = 1 MathF.Sign(val2) = -1
Example
Let us now see another example to implement the MathF.Sign() method −
using System; public class Demo { public static void Main(){ float val1 = 0.00f; float val2 = -10.6735f; Console.WriteLine("MathF.Sign(val1) = "+MathF.Sign(val1)); Console.WriteLine("MathF.Sign(val2) = "+MathF.Sign(val2)); } }
Output
This will produce the following output −
MathF.Sign(val1) = 0 MathF.Sign(val2) = -1
- Related Articles
- MathF.Tan() Method in C# with Examples
- MathF.Tanh() Method in C# with Examples
- MathF.Truncate() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- MathF.Sinh() Method in C# with Examples
- MathF.Sqrt() Method in C# with Examples
- Boolean.GetHashCode() Method in C# with Examples
- Single.Equals() Method in C# with Examples
- Single.CompareTo() Method in C# with Examples
- SByte.ToString() Method in C# with Examples
- Boolean.GetTypeCode() Method in C# with Examples
- Double.CompareTo Method in C# with Examples
- Double.Equals() Method in C# with Examples
- Single.IsPositiveInfinity() Method in C# with Examples
- Single.GetTypeCode Method in C# with Examples

Advertisements