Guid.TryParse 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
TryParse(ReadOnlySpan<Char>, Guid) |
GUID의 표현을 포함하는 지정된 읽기 전용 문자 범위를 해당하는 Guid 구조체로 변환합니다. |
TryParse(String, Guid) |
GUID의 문자열 표현을 해당 Guid 구조체로 변환합니다. |
TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid) |
문자 범위를 값으로 구문 분석하려고 합니다. |
TryParse(String, IFormatProvider, Guid) |
문자열을 값으로 구문 분석하려고 합니다. |
TryParse(ReadOnlySpan<Char>, Guid)
GUID의 표현을 포함하는 지정된 읽기 전용 문자 범위를 해당하는 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
매개 변수
- input
- ReadOnlySpan<Char>
변환할 GUID를 나타내는 문자를 포함하는 범위입니다.
- result
- Guid
이 메서드를 반환하면 구문 분석된 값이 포함됩니다. 메서드가 true
를 반환하면 result
에 유효한 Guid가 포함됩니다. 메서드가 false
를 반환하는 경우 result
는 Empty와 같습니다.
반환
구문 분석 작업에 성공하면 true
이고, 그렇지 않으면 false
입니다.
적용 대상
TryParse(String, Guid)
GUID의 문자열 표현을 해당 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
매개 변수
- input
- String
변환할 GUID를 포함하는 문자열입니다.
- result
- Guid
이 메서드를 반환하면 구문 분석된 값이 포함됩니다. 메서드가 true
를 반환하면 result
에 유효한 Guid가 포함됩니다. 메서드가 false
를 반환하는 경우 result
는 Empty와 같습니다.
반환
구문 분석 작업에 성공하면 true
이고, 그렇지 않으면 false
입니다.
예제
다음 예제에서는 새 GUID를 만들고 "B", "D" 및 "X" 형식 지정자를 사용하여 메서드를 호출 ToString(String) 하여 세 개의 개별 문자열 표현으로 변환한 다음 메서드를 호출 TryParse 하여 문자열을 다시 값으로 Guid 변환합니다.
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
설명
이 메서드는 구문 분석된 GUID를 반환하는 대신 가 인식된 형식인지 여부를 반환 false
input
null
하고 예외를 throw하지 않는다는 점을 제외하고 메서드와 비슷합니다.Parse 다음 표와 같이 선행 또는 후행 공백 input
을 잘라내고 및 ToString(String, IFormatProvider) 메서드에서 인식되는 ToString(String) 5가지 형식 중 하나로 문자열을 변환합니다.
지정자 | 설명 | 서식 |
---|---|---|
N |
32자리 숫자 | 00000000000000000000000000000000 |
D |
하이픈으로 구분된 32자리 숫자 | 00000000-0000-0000-0000-000000000000 |
B |
하이픈으로 구분된 32자리 숫자, 중괄호로 묶인 숫자 | {00000000-0000-0000-0000-000000000000} |
P |
괄호로 묶인 하이픈으로 구분된 32자리 숫자 | (00000000-0000-0000-0000-000000000000) |
X |
중괄호로 묶인 4개의 16진수 값입니다. 여기서 네 번째 값은 중괄호로 묶인 8개의 16진수 값의 하위 집합입니다. | {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} |
추가 정보
적용 대상
TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid)
문자 범위를 값으로 구문 분석하려고 합니다.
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
매개 변수
- s
- ReadOnlySpan<Char>
구문 분석할 문자의 범위입니다.
- provider
- IFormatProvider
s
에 대한 문화권별 서식 정보를 제공하는 개체입니다.
- result
- Guid
이 메서드가 반환될 때 에는 성공적으로 구문 분석 s
한 결과 또는 실패 시 정의되지 않은 값이 포함됩니다.
반환
true
가 성공적으로 구문 분석되었으면 s
이고, false
그렇지 않으면 입니다.
적용 대상
TryParse(String, IFormatProvider, Guid)
문자열을 값으로 구문 분석하려고 합니다.
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
매개 변수
- s
- String
구문 분석할 문자열입니다.
- provider
- IFormatProvider
s
에 대한 문화권별 서식 정보를 제공하는 개체입니다.
- result
- Guid
이 메서드가 반환될 때 실패 시 성공적으로 구문 분석 s
한 결과 또는 정의되지 않은 값이 포함됩니다.
반환
true
가 성공적으로 구문 분석되었으면 s
이고, false
그렇지 않으면 입니다.