當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C# Single.IsNegative()用法及代碼示例


Single.IsNegative(Single)方法用於返回一個值,該值指示指定的數字是否為負。

用法: public static bool IsNegative (float f);

返回值:如果f取值為Negative,則此方法返回true,否則返回false。


以下示例程序旨在說明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

參考:



相關用法


注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Single.IsNegative() Method in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。