Guid.TryParse Méthode

Définition

Surcharges

Nom Description
TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid)

Tente d’analyser une étendue de caractères en une valeur.

TryParse(ReadOnlySpan<Byte>, Guid)
TryParse(ReadOnlySpan<Char>, Guid)

Convertit l’étendue de caractères en lecture seule spécifiée contenant la représentation d’un GUID en structure équivalente Guid .

TryParse(String, Guid)

Convertit la représentation sous forme de chaîne d’un GUID en structure équivalente Guid .

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Guid)

Tente d’analyser une étendue de caractères UTF-8 en une valeur.

TryParse(String, IFormatProvider, Guid)

Tente d’analyser une chaîne en une valeur.

TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid)

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

Tente d’analyser une étendue de caractères en une valeur.

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

Paramètres

s
ReadOnlySpan<Char>

Étendue de caractères à analyser.

provider
IFormatProvider

Objet qui fournit des informations de mise en forme spécifiques à la culture sur s.

result
Guid

Lorsque cette méthode est retournée, contient le résultat de l’analyse sréussie ou d’une valeur non définie en cas d’échec.

Retours

true si s elle a été analysée avec succès ; sinon, false.

S’applique à

TryParse(ReadOnlySpan<Byte>, Guid)

Source:
Guid.cs
Source:
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

Paramètres

utf8Text
ReadOnlySpan<Byte>
result
Guid

Retours

S’applique à

TryParse(ReadOnlySpan<Char>, Guid)

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

Convertit l’étendue de caractères en lecture seule spécifiée contenant la représentation d’un GUID en structure équivalente Guid .

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

Paramètres

input
ReadOnlySpan<Char>

Étendue contenant les caractères représentant le GUID à convertir.

result
Guid

Lorsque cette méthode est retournée, contient la valeur analysée. Si la méthode retourne true, result contient une valeur valide Guid. Si la méthode retourne false, result est Emptyégale .

Retours

true si l’opération d’analyse a réussi ; sinon, false.

S’applique à

TryParse(String, Guid)

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

Convertit la représentation sous forme de chaîne d’un GUID en structure équivalente Guid .

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

Paramètres

input
String

Chaîne contenant le GUID à convertir.

result
Guid

Lorsque cette méthode est retournée, contient la valeur analysée. Si la méthode retourne true, result contient une valeur valide Guid. Si la méthode retourne false, result est Emptyégale .

Retours

true si l’opération d’analyse a réussi ; sinon, false.

Exemples

L’exemple suivant crée un GUID, le convertit en trois représentations de chaîne distinctes en appelant la ToString(String) méthode avec les spécificateurs de format « B », « D » et « X », puis appelle la TryParse méthode pour convertir les chaînes en Guid valeurs.

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

Remarques

Cette méthode est semblable à la Parse méthode, sauf qu’au lieu de retourner le GUID analysé, elle retourne false si input elle est null ou non dans un format reconnu et ne lève pas d’exception. Il supprime tout espace blanc de début ou de fin et input convertit les chaînes dans l’un des cinq formats reconnus par les ToString(String) méthodes et ToString(String, IFormatProvider) les méthodes, comme indiqué dans le tableau suivant.

Spécificateur Description Format
N 32 chiffres 00000000000000000000000000000000
D 32 chiffres séparés par des traits d’union 00000000-0000-0000-0000-000000000000
B 32 chiffres séparés par des traits d’union, placés entre accolades {00000000-0000-0000-0000-000000000000}
P 32 chiffres séparés par des traits d’union, placés entre parenthèses (00000000-0000-0000-0000-000000000000)
X Quatre valeurs hexadécimales placées entre accolades, où la quatrième valeur est un sous-ensemble de huit valeurs hexadécimales qui sont également placées entre accolades {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}

Voir aussi

S’applique à

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Guid)

Source:
Guid.cs
Source:
Guid.cs

Tente d’analyser une étendue de caractères UTF-8 en une valeur.

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

Paramètres

utf8Text
ReadOnlySpan<Byte>

Étendue de caractères UTF-8 à analyser.

provider
IFormatProvider

Objet qui fournit des informations de mise en forme spécifiques à la culture sur utf8Text.

result
Guid

Lors du retour, contient le résultat de l’analyse utf8Text réussie ou d’une valeur non définie en cas d’échec.

Retours

true si utf8Text elle a été analysée avec succès ; sinon, false.

S’applique à

TryParse(String, IFormatProvider, Guid)

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

Tente d’analyser une chaîne en une valeur.

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

Paramètres

s
String

Chaîne à analyser.

provider
IFormatProvider

Objet qui fournit des informations de mise en forme spécifiques à la culture sur s.

result
Guid

Lorsque cette méthode est retournée, contient le résultat de l’analyse s réussie ou d’une valeur non définie en cas d’échec.

Retours

true si s elle a été analysée avec succès ; sinon, false.

S’applique à