Single.IsNegative() Method in C# with Examples

Single.IsNegative(Single) Method is used to return a value indicating whether the specified number evaluates to negative or not.

Syntax: public static bool IsNegative (float f);

Return Value: This method returns the true if f evaluates to Negative otherwise it returns false.

Below programs illustrate the use of Single.IsNegative() Method:

Example 1:




// C# program to demonstrate the
// Single.IsNegative() Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing value1
        float value1 = 1011.5615f;
  
        // using IsNegative() method
        bool value = Single.IsNegative(value1);
  
        // Displaying the result
        if (value)
            Console.WriteLine("{0} is Negative", value1);
        else
            Console.WriteLine("{0} is not Negative", value1);
    }
}


Output:

1011.562 is not Negative

Example 2:




// C# program to demonstrate the
// Single.IsNegative() Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing value1
        float value1 = -10.651f;
  
        // using IsNegative() method
        bool value = Single.IsNegative(value1);
  
        // Displaying the result
        if (value)
            Console.WriteLine("{0} is Negative", value1);
        else
            Console.WriteLine("{0} is not Negative", value1);
    }
}


Output:

-10.651 is Negative

Reference:

  • https://docs.microsoft.com/en-us/dotnet/api/system.single.isnegative?view=netstandard-2.1


Contact Us