当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET Math.Sign方法代码示例

本文整理汇总了VB.NET中System.Math.Sign方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Math.Sign方法的具体用法?VB.NET Math.Sign怎么用?VB.NET Math.Sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Math的用法示例。


在下文中一共展示了Math.Sign方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Sample

' This example demonstrates Math.Sign()
Class Sample
   Public Shared Sub Main()
      Dim str As String = "{0}: {1,3} is {2} zero."
      Dim nl As String = Environment.NewLine
      
      Dim xByte1 As Byte = 0
      Dim xShort1 As Short = -2
      Dim xInt1 As Integer = -3
      Dim xLong1 As Long = -4
      Dim xSingle1 As Single = 0F
      Dim xDouble1 As Double = 6.0
      Dim xDecimal1 As [Decimal] = -7D
      
      ' The following type is not CLS-compliant.
      Dim xSbyte1 As SByte = -101
      
      Console.WriteLine("{0}Test the sign of the following types of values:", nl)
      Console.WriteLine(str, "Byte   ", xByte1, Test(Math.Sign(xByte1)))
      Console.WriteLine(str, "Int16  ", xShort1, Test(Math.Sign(xShort1)))
      Console.WriteLine(str, "Int32  ", xInt1, Test(Math.Sign(xInt1)))
      Console.WriteLine(str, "Int64  ", xLong1, Test(Math.Sign(xLong1)))
      Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)))
      Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)))
      Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)))
      '
      Console.WriteLine("{0}The following type is not CLS-compliant.", nl)
      Console.WriteLine(str, "SByte  ", xSbyte1, Test(Math.Sign(xSbyte1)))
   End Sub
   '
   Public Shared Function Test([compare] As Integer) As [String]
      If [compare] = 0 Then
         Return "equal to"
      ElseIf [compare] < 0 Then
         Return "less than"
      Else
         Return "greater than"
      End If
   End Function 'Test
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:40,代码来源:Math.Sign

输出:

Test the sign of the following types of values:
Byte   :   0 is equal to zero.
Int16  :  -2 is less than zero.
Int32  :  -3 is less than zero.
Int64  :  -4 is less than zero.
Single :   0 is equal to zero.
Double :   6 is greater than zero.
Decimal:  -7 is less than zero.

The following type is not CLS-compliant.
SByte  : -101 is less than zero.

示例2: MainClass

' 导入命名空间
Imports System

public class MainClass
   Shared Sub Main()

        Console.WriteLine(System.Math.Sign(-1))
        Console.WriteLine(System.Math.Sign(0))
        Console.WriteLine(System.Math.Sign(1))
   End Sub
End Class
开发者ID:VB程序员,项目名称:System,代码行数:11,代码来源:Math.Sign


注:本文中的System.Math.Sign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。