本文整理匯總了VB.NET中System.Guid.TryParseExact方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Guid.TryParseExact方法的具體用法?VB.NET Guid.TryParseExact怎麽用?VB.NET Guid.TryParseExact使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Guid
的用法示例。
在下文中一共展示了Guid.TryParseExact方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
Module Example
Public Sub Main()
' Define an array of all format specifiers.
Dim formats() As String = { "N", "D", "B", "P", "X" }
Dim guid As Guid = Guid.NewGuid()
' Create an array of valid Guid string representations.
Dim stringGuids(formats.Length - 1) As String
For ctr As Integer = 0 To formats.Length - 1
stringGuids(ctr) = guid.ToString(formats(ctr))
Next
' Try to parse the strings in the array using the "B" format specifier.
For Each stringGuid In stringGuids
Dim newGuid As Guid
If Guid.TryParseExact(stringGuid, "B", newGuid) Then
Console.WriteLine("Successfully parsed {0}", stringGuid)
Else
Console.WriteLine("Unable to parse '{0}'", stringGuid)
End If
Next
End Sub
End Module
輸出:
Unable to parse 'c0fb150f6bf344df984a3a0611ae5e4a' Unable to parse 'c0fb150f-6bf3-44df-984a-3a0611ae5e4a' Successfully parsed {c0fb150f-6bf3-44df-984a-3a0611ae5e4a} Unable to parse '(c0fb150f-6bf3-44df-984a-3a0611ae5e4a)' Unable to parse '{0xc0fb150f,0x6bf3,0x44df,{0x98,0x4a,0x3a,0x06,0x11,0xae,0x5e,0x4a}}'