Guid.TryParse Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Overloads
| Name | Description |
|---|---|
| TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid) |
Probeert een reeks tekens te parseren in een waarde. |
| TryParse(ReadOnlySpan<Byte>, Guid) | |
| TryParse(ReadOnlySpan<Char>, Guid) |
Converteert de opgegeven alleen-lezen periode van tekens die de weergave van een GUID bevatten naar de equivalente Guid structuur. |
| TryParse(String, Guid) |
Converteert de tekenreeksweergave van een GUID naar de equivalente Guid structuur. |
| TryParse(ReadOnlySpan<Byte>, IFormatProvider, Guid) |
Probeert een reeks UTF-8 tekens te parseren in een waarde. |
| TryParse(String, IFormatProvider, Guid) |
Probeert een tekenreeks te parseren in een waarde. |
TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid)
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
Probeert een reeks tekens te parseren in een waarde.
public:
static bool TryParse(ReadOnlySpan<char> s, IFormatProvider ^ provider, [Runtime::InteropServices::Out] Guid % result) = ISpanParsable<Guid>::TryParse;
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Guid result);
static member TryParse : ReadOnlySpan<char> * IFormatProvider * Guid -> bool
Public Shared Function TryParse (s As ReadOnlySpan(Of Char), provider As IFormatProvider, ByRef result As Guid) As Boolean
Parameters
- s
- ReadOnlySpan<Char>
De reeks tekens die moeten worden geparseerd.
- provider
- IFormatProvider
Een object dat cultuurspecifieke opmaakinformatie biedt over s.
- result
- Guid
Wanneer deze methode wordt geretourneerd, bevat het resultaat van het parseren sof een niet-gedefinieerde waarde bij een fout.
Retouren
trueindien s geparseerd; anders. false
Van toepassing op
TryParse(ReadOnlySpan<Byte>, Guid)
- Bron:
- Guid.cs
- Bron:
- Guid.cs
public:
static bool TryParse(ReadOnlySpan<System::Byte> utf8Text, [Runtime::InteropServices::Out] Guid % result);
public static bool TryParse(ReadOnlySpan<byte> utf8Text, out Guid result);
static member TryParse : ReadOnlySpan<byte> * Guid -> bool
Public Shared Function TryParse (utf8Text As ReadOnlySpan(Of Byte), ByRef result As Guid) As Boolean
Parameters
- utf8Text
- ReadOnlySpan<Byte>
- result
- Guid
Retouren
Van toepassing op
TryParse(ReadOnlySpan<Char>, Guid)
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
Converteert de opgegeven alleen-lezen periode van tekens die de weergave van een GUID bevatten naar de equivalente Guid structuur.
public:
static bool TryParse(ReadOnlySpan<char> input, [Runtime::InteropServices::Out] Guid % result);
public static bool TryParse(ReadOnlySpan<char> input, out Guid result);
static member TryParse : ReadOnlySpan<char> * Guid -> bool
Public Shared Function TryParse (input As ReadOnlySpan(Of Char), ByRef result As Guid) As Boolean
Parameters
- input
- ReadOnlySpan<Char>
Een bereik met de tekens die de GUID vertegenwoordigen die moeten worden geconverteerd.
- result
- Guid
Wanneer deze methode wordt geretourneerd, bevat deze de geparseerde waarde. Als de methode retourneert true, result bevat het een geldige Guidwaarde. Als de methode retourneert false, result is dit gelijk aan Empty.
Retouren
true als de parseringsbewerking is geslaagd; anders, false.
Van toepassing op
TryParse(String, Guid)
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
Converteert de tekenreeksweergave van een GUID naar de equivalente Guid structuur.
public:
static bool TryParse(System::String ^ input, [Runtime::InteropServices::Out] Guid % result);
public static bool TryParse(string input, out Guid result);
public static bool TryParse(string? input, out Guid result);
static member TryParse : string * Guid -> bool
Public Shared Function TryParse (input As String, ByRef result As Guid) As Boolean
Parameters
- input
- String
Een tekenreeks met de GUID die moet worden geconverteerd.
- result
- Guid
Wanneer deze methode wordt geretourneerd, bevat deze de geparseerde waarde. Als de methode retourneert true, result bevat het een geldige Guidwaarde. Als de methode retourneert false, result is dit gelijk aan Empty.
Retouren
true als de parseringsbewerking is geslaagd; anders, false.
Voorbeelden
In het volgende voorbeeld wordt een nieuwe GUID gemaakt, geconverteerd naar drie afzonderlijke tekenreeksweergaven door de ToString(String) methode aan te roepen met de notatieaanduidingen B, D en X, en wordt de TryParse methode vervolgens aangeroepen om de tekenreeksen weer te converteren naar Guid waarden.
Guid originalGuid = Guid.NewGuid();
// Create an array of string representations of the GUID.
string[] stringGuids = { originalGuid.ToString("B"),
originalGuid.ToString("D"),
originalGuid.ToString("X") };
// Parse each string representation.
foreach (var stringGuid in stringGuids)
{
if (Guid.TryParse(stringGuid, out var newGuid))
Console.WriteLine($"Converted {stringGuid} to a Guid");
else
Console.WriteLine($"Unable to convert {stringGuid} to a Guid");
}
// The example displays output similar to the following:
//
// Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
// Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
// Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid
open System
let originalGuid = Guid.NewGuid()
// Create an array of string representations of the GUID.
let stringGuids =
[| originalGuid.ToString "B"
originalGuid.ToString "D"
originalGuid.ToString "X" |]
// Parse each string representation.
for stringGuid in stringGuids do
match Guid.TryParse stringGuid with
| true, newGuid ->
printfn $"Converted {stringGuid} to a Guid"
| _ ->
printfn $"Unable to convert {stringGuid} to a Guid"
// The example displays output similar to the following:
//
// Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
// Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
// Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid
Module Example
Public Sub Main()
Dim originalGuid As Guid = Guid.NewGuid()
' Create an array of string representations of the GUID.
Dim stringGuids() As String = { originalGuid.ToString("B"),
originalGuid.ToString("D"),
originalGuid.ToString("X") }
' Parse each string representation.
Dim newGuid As Guid
For Each stringGuid In stringGuids
If Guid.TryParse(stringGuid, newGuid) Then
Console.WriteLine("Converted {0} to a Guid", stringGuid)
Else
Console.WriteLine("Unable to convert {0} to a Guid",
stringGuid)
End If
Next
End Sub
End Module
' The example displays the following output:
' Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
' Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
' Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid
Opmerkingen
Deze methode is net als de Parse methode, behalve dat in plaats van de geparseerde GUID te retourneren, deze retourneert false als inputnull deze zich in een herkende indeling bevindt en geen uitzondering genereert. Hiermee wordt alle voorloop- of volgspaties van input en converteert u tekenreeksen in een van de vijf indelingen die worden herkend door de ToString(String) en ToString(String, IFormatProvider) methoden, zoals wordt weergegeven in de volgende tabel.
| Specificator | Beschrijving | Format |
|---|---|---|
N |
32 cijfers | 00000000000000000000000000000000 |
D |
32 cijfers gescheiden door afbreekstreepjes | 00000000-0000-0000-0000-000000000000 |
B |
32 cijfers gescheiden door afbreekstreepjes, tussen accolades | {00000000-0000-0000-0000-000000000000} |
P |
32 cijfers gescheiden door afbreekstreepjes, tussen haakjes | (00000000-0000-0000-0000-000000000000) |
X |
Vier hexadecimale waarden tussen accolades, waarbij de vierde waarde een subset is van acht hexadecimale waarden die ook tussen accolades zijn opgenomen | {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} |
Zie ook
Van toepassing op
TryParse(ReadOnlySpan<Byte>, IFormatProvider, Guid)
- Bron:
- Guid.cs
- Bron:
- Guid.cs
Probeert een reeks UTF-8 tekens te parseren in een waarde.
public:
static bool TryParse(ReadOnlySpan<System::Byte> utf8Text, IFormatProvider ^ provider, [Runtime::InteropServices::Out] Guid % result) = IUtf8SpanParsable<Guid>::TryParse;
public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out Guid result);
static member TryParse : ReadOnlySpan<byte> * IFormatProvider * Guid -> bool
Public Shared Function TryParse (utf8Text As ReadOnlySpan(Of Byte), provider As IFormatProvider, ByRef result As Guid) As Boolean
Parameters
- utf8Text
- ReadOnlySpan<Byte>
Het bereik van UTF-8 tekens om te parseren.
- provider
- IFormatProvider
Een object dat cultuurspecifieke opmaakinformatie biedt over utf8Text.
- result
- Guid
Bij retour bevat het resultaat van het parseren utf8Text of een niet-gedefinieerde waarde bij een fout.
Retouren
trueindien utf8Text geparseerd; anders. false
Van toepassing op
TryParse(String, IFormatProvider, Guid)
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
- Bron:
- Guid.cs
Probeert een tekenreeks te parseren in een waarde.
public:
static bool TryParse(System::String ^ s, IFormatProvider ^ provider, [Runtime::InteropServices::Out] Guid % result) = IParsable<Guid>::TryParse;
public static bool TryParse(string? s, IFormatProvider? provider, out Guid result);
static member TryParse : string * IFormatProvider * Guid -> bool
Public Shared Function TryParse (s As String, provider As IFormatProvider, ByRef result As Guid) As Boolean
Parameters
- s
- String
De tekenreeks die moet worden geparseerd.
- provider
- IFormatProvider
Een object dat cultuurspecifieke opmaakinformatie biedt over s.
- result
- Guid
Wanneer deze methode wordt geretourneerd, bevat dit het resultaat van het parseren s of van een niet-gedefinieerde waarde bij een fout.
Retouren
trueindien s geparseerd; anders. false