本文整理匯總了VB.NET中System.Guid.CompareTo方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Guid.CompareTo方法的具體用法?VB.NET Guid.CompareTo怎麽用?VB.NET Guid.CompareTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Guid
的用法示例。
在下文中一共展示了Guid.CompareTo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
Module Example
Public Sub Main()
Dim mainGuid As Guid = Guid.Parse("01e75c83-c6f5-4192-b57e-7427cec5560d")
Dim guid2 As New Guid(&h01e75c83,
BitConverter.ToInt16(new Byte() { &hf5, &hc6 }, 0),
&h4192,
new Byte() { &hb5, &h7e, &h74, &h27, &hce, &hc5, &h56, &h0c} )
Dim guid3 As Guid = Guid.Parse("01e75c84-c6f5-4192-b57e-7427cec5560d")
Console.WriteLine("{0} {1:F} {2}", mainGuid,
CType(mainGuid.CompareTo(guid2), Comparison), guid2)
Console.WriteLine("{0} {1:F} {2}", mainGuid,
CType(mainGuid.CompareTo(guid3), Comparison), guid3)
End Sub
Private Enum Comparison As Integer
LessThan = -1
Equals = 0
GreaterThan = 1
End Enum
End Module
輸出:
01e75c83-c6f5-4192-b57e-7427cec5560d GreaterThan 01e75c83-c6f5-4192-b57e-7427cec5560c 01e75c83-c6f5-4192-b57e-7427cec5560d LessThan 01e75c84-c6f5-4192-b57e-7427cec5560d
示例2: Example
' 導入命名空間
Imports System.Runtime.InteropServices
<Guid("936DA01F-9ABD-4d9d-80C7-02AF85C822A8")>
Module Example
Public Sub Main()
Dim guidAttr As GuidAttribute = CType(Attribute.GetCustomAttribute(GetType(Example),
GetType(GuidAttribute)), GuidAttribute)
Dim guidValue As Guid = Guid.Parse(guidAttr.Value)
Dim values() As Object = { Nothing, 16,
Guid.Parse("01e75c83-c6f5-4192-b57e-7427cec5560d"),
guidValue }
For Each value In values
Try
Console.WriteLine("{0} and {1}: {2}", guidValue,
If(value Is Nothing, "null", value),
guidValue.CompareTo(value))
Catch e As ArgumentException
Console.WriteLine("Cannot compare {0} and {1}", guidValue,
If(value Is Nothing, "null", value))
End Try
Next
End Sub
End Module
輸出:
936da01f-9abd-4d9d-80c7-02af85c822a8 and null: 1 Cannot compare 936da01f-9abd-4d9d-80c7-02af85c822a8 and 16 936da01f-9abd-4d9d-80c7-02af85c822a8 and 01e75c83-c6f5-4192-b57e-7427cec5560d: 1 936da01f-9abd-4d9d-80c7-02af85c822a8 and 936da01f-9abd-4d9d-80c7-02af85c822a8: 0