在C#中, 符号() 是一个数学类方法,它返回一个指定数字符号的整数。通过如下更改传递参数的数据类型,可以重载此方法:
null
- 数学符号(十进制): 返回指定十进制数符号的整数。
- 数学签名(双人): 返回指定双精度浮点数符号的整数。
- 数学签名(Int16): 返回指定16位有符号整数的符号的整数。在这里 Int16 是 短的 数据类型
- 数学签名(Int32): 返回指定32位有符号整数的符号的整数。在这里 Int32 是 智力 数据类型。
- 数学签名(Int64): 返回指定64位有符号整数的符号的整数。在这里 Int64 是 长的 数据类型。
- 数学符号(SByte): 返回指定8位有符号整数的符号的整数。
- 数学签名(单张): 返回指定单精度浮点数符号的整数。在这里 仅有一个的 是 浮动 数据类型。
以上所有方法的通用语法:
public static int Sign(data_type value)
参数: 此方法采用以下形式的单个参数: 字节、int、double、sbyte等。
返回类型: 此方法返回类型为的值 系统Int32 根据以下提到的条件:
返回值 | 条件: |
---|---|
0 | 如果值等于零 |
1. | 如果值大于零 |
-1 | 如果值小于零 |
例子:
// C# program to demonstrate the // Math.Sign() method using System; class GFG { // Main Method static void Main( string [] args) { // Decimal data type Decimal de = 150M; // Double data type Double d = 34.5432d; // Int16 data type short sh = 0; // Int32 data type int i = -5678; // Int64 data type long l = 598964564; // SByte data type sbyte sb = -34; // float data type float f = 56.89f; // displaying result Console.WriteLine( "Decimal: " + de + " " + check(Math.Sign(de))); Console.WriteLine( "Double: " + d + " " + check(Math.Sign(d))); Console.WriteLine( "Int16: " + sh + " " + check(Math.Sign(sh))); Console.WriteLine( "Int32: " + i + " " + check(Math.Sign(i))); Console.WriteLine( "Int64: " + l + " " + check(Math.Sign(l))); Console.WriteLine( "SByte: " + sb + " " + check(Math.Sign(sb))); Console.WriteLine( "Single: " + f + " " + check(Math.Sign(f))); } // function to check whether the input // number is greater than zero or not public static String check( int compare) { if (compare == 0) return "equal to zero" ; else if (compare < 0) return "less than zero" ; else return "greater than zero" ; } } |
输出:
Decimal: 150 greater than zero Double: 34.5432 greater than zero Int16: 0 equal to zero Int32: -5678 less than zero Int64: 598964564 greater than zero SByte: -34 less than zero Single: 56.89 greater than zero
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END