📜  C#中的Single.IsNegative()方法与示例

📅  最后修改于: 2021-05-29 17:28:22             🧑  作者: Mango

Single.IsNegative(Single)方法用于返回一个值,该值指示指定的数字是否为负。

下面的程序说明了Single.IsNegative()方法的用法:

范例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);
    }
}
输出:
1011.562 is not Negative

范例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);
    }
}
输出:
-10.651 is Negative

参考:

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