本文整理汇总了VB.NET中System.Numerics.BigInteger.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:VB.NET BigInteger.CompareTo方法的具体用法?VB.NET BigInteger.CompareTo怎么用?VB.NET BigInteger.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.CompareTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: values
Dim values() As Object = { BigInteger.Pow(Int64.MaxValue, 10), Nothing,
12.534, Int64.MaxValue, BigInteger.One }
Dim number As BigInteger = UInt64.MaxValue
For Each value As Object In values
Try
Console.WriteLine("Comparing {0} with '{1}': {2}", number, value,
number.CompareTo(value))
Catch e As ArgumentException
Console.WriteLine("Unable to compare the {0} value {1} with a BigInteger.",
value.GetType().Name, value)
End Try
Next
输出:
Comparing 18446744073709551615 with '4.4555084156466750133735972424E+189': -1 Comparing 18446744073709551615 with '': 1 Unable to compare the Double value 12.534 with a BigInteger. Unable to compare the Int64 value 9223372036854775807 with a BigInteger. Comparing 18446744073709551615 with '1': 1
示例2:
Dim bigIntValue As BigInteger = BigInteger.Parse("3221123045552")
Dim byteValue As Byte = 16
Dim sbyteValue As SByte = -16
Dim shortValue As Short = 1233
Dim ushortValue As UShort = 1233
Dim intValue As Integer = -12233
Dim uintValue As UInteger = 12233
Dim longValue As Long = 12382222
Dim ulongValue As Integer = 1238222
Console.WriteLine("Comparing {0} with {1}: {2}", _
bigIntValue, byteValue, _
bigIntValue.CompareTo(byteValue))
Console.WriteLine("Comparing {0} with {1}: {2}", _
bigIntValue, sbyteValue, _
bigIntValue.CompareTo(sbyteValue))
Console.WriteLine("Comparing {0} with {1}: {2}", _
bigIntValue, shortValue, _
bigIntValue.CompareTo(shortValue))
Console.WriteLine("Comparing {0} with {1}: {2}", _
bigIntValue, ushortValue, _
bigIntValue.CompareTo(ushortValue))
Console.WriteLine("Comparing {0} with {1}: {2}", _
bigIntValue, intValue, _
bigIntValue.CompareTo(intValue))
Console.WriteLine("Comparing {0} with {1}: {2}", _
bigIntValue, uintValue, _
bigIntValue.CompareTo(uintValue))
Console.WriteLine("Comparing {0} with {1}: {2}", _
bigIntValue, longValue, _
bigIntValue.CompareTo(longValue))
Console.WriteLine("Comparing {0} with {1}: {2}", _
bigIntValue, ulongValue, _
bigIntValue.CompareTo(ulongValue))
输出:
Comparing 3221123045552 with 16: 1 Comparing 3221123045552 with -16: 1 Comparing 3221123045552 with 1233: 1 Comparing 3221123045552 with 1233: 1 Comparing 3221123045552 with -12233: 1 Comparing 3221123045552 with 12233: 1 Comparing 3221123045552 with 12382222: 1 Comparing 3221123045552 with 1238222: 1
示例3: New
' 导入命名空间
Imports System.Collections.Generic
Imports System.Numerics
Public Structure StarInfo : Implements IComparable(Of StarInfo)
' Define constructors.
Public Sub New(name As String, lightYears As Double)
Me.Name = name
' Calculate distance in miles from light years.
Me.Distance = CType(Math.Round(lightYears * 5.88e12), BigInteger)
End Sub
Public Sub New(name As String, distance As BigInteger)
Me.Name = name
Me.Distance = distance
End Sub
' Define public fields.
Public Name As String
Public Distance As BigInteger
' Display name of star and its distance in parentheses.
Public Overrides Function ToString() As String
Return String.Format("{0,-10} ({1:N0})", Me.Name, Me.Distance)
End Function
' Compare StarInfo objects by their distance from Earth.
Public Function CompareTo(other As starInfo) As Integer _
Implements IComparable(Of StarInfo).CompareTo
Return Me.Distance.CompareTo(other.Distance)
End Function
End Structure
示例4: Main
Module Example
Public Sub Main()
Dim star As StarInfo
Dim stars As New List(Of StarInfo)
star = New StarInfo("Sirius", 8.6d)
stars.Add(star)
star = New StarInfo("Rigel", 1400d)
stars.Add(star)
star = New StarInfo("Castor", 49d)
stars.Add(star)
star = New StarInfo("Antares", 520d)
stars.Add(star)
stars.Sort()
For Each star In stars
Console.WriteLine(star)
Next
End Sub
End Module
输出:
Sirius (50,568,000,000,000) Castor (288,120,000,000,000) Antares (3,057,600,000,000,000) Rigel (8,232,000,000,000,000)