本文整理汇总了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}}'