Uri.TryCreate 方法

定義

建立新的 UriCreates a new Uri. 如果無法建立 Uri,不會擲回例外狀況。Does not throw an exception if the Uri cannot be created.

多載

TryCreate(String, UriKind, Uri)

使用指定的 Uri 執行個體和 String,建立新的 UriKindCreates a new Uri using the specified String instance and a UriKind.

TryCreate(Uri, String, Uri)

使用指定的基底和相對 Uri 執行個體,建立新的 StringCreates a new Uri using the specified base and relative String instances.

TryCreate(Uri, Uri, Uri)

使用指定的基底和相對 Uri 執行個體,建立新的 UriCreates a new Uri using the specified base and relative Uri instances.

TryCreate(String, UriKind, Uri)

使用指定的 Uri 執行個體和 String,建立新的 UriKindCreates a new Uri using the specified String instance and a UriKind.

public:
 static bool TryCreate(System::String ^ uriString, UriKind uriKind, [Runtime::InteropServices::Out] Uri ^ % result);
public static bool TryCreate (string uriString, UriKind uriKind, out Uri result);
public static bool TryCreate (string? uriString, UriKind uriKind, out Uri? result);
static member TryCreate : string * UriKind * Uri -> bool
Public Shared Function TryCreate (uriString As String, uriKind As UriKind, ByRef result As Uri) As Boolean

參數

uriString
String

Uri 的字串表示。The string representation of the Uri.

uriKind
UriKind

URI 的類型。The type of the Uri.

result
Uri

這個方法傳回時,會包含建構的 UriWhen this method returns, contains the constructed Uri.

傳回

Boolean

如果已成功建立 Uri 則為 true,否則為 falsetrue if the Uri was successfully created; otherwise, false.

備註

如果此方法傳回 true ,則新的 Uri 會在中 resultIf this method returns true, the new Uri is in result.

適用於

TryCreate(Uri, String, Uri)

使用指定的基底和相對 Uri 執行個體,建立新的 StringCreates a new Uri using the specified base and relative String instances.

public:
 static bool TryCreate(Uri ^ baseUri, System::String ^ relativeUri, [Runtime::InteropServices::Out] Uri ^ % result);
public static bool TryCreate (Uri baseUri, string relativeUri, out Uri result);
public static bool TryCreate (Uri? baseUri, string? relativeUri, out Uri? result);
static member TryCreate : Uri * string * Uri -> bool
Public Shared Function TryCreate (baseUri As Uri, relativeUri As String, ByRef result As Uri) As Boolean

參數

baseUri
Uri

基底 URI。The base URI.

relativeUri
String

要加入基底 Uri 之相對 URI 的字串表示。The string representation of the relative URI to add to the base Uri.

result
Uri

當這個方法傳回時,會包含從 UribaseUri 建構的 relativeUriWhen this method returns, contains a Uri constructed from baseUri and relativeUri. 這個參數會以未初始化的狀態傳遞。This parameter is passed uninitialized.

傳回

Boolean

如果已成功建立 Uri 則為 true,否則為 falsetrue if the Uri was successfully created; otherwise, false.

備註

如果此方法傳回 true ,則新的 Uri 會在中 resultIf this method returns true, the new Uri is in result.

適用於

TryCreate(Uri, Uri, Uri)

使用指定的基底和相對 Uri 執行個體,建立新的 UriCreates a new Uri using the specified base and relative Uri instances.

public:
 static bool TryCreate(Uri ^ baseUri, Uri ^ relativeUri, [Runtime::InteropServices::Out] Uri ^ % result);
public static bool TryCreate (Uri baseUri, Uri relativeUri, out Uri result);
public static bool TryCreate (Uri? baseUri, Uri? relativeUri, out Uri? result);
static member TryCreate : Uri * Uri * Uri -> bool
Public Shared Function TryCreate (baseUri As Uri, relativeUri As Uri, ByRef result As Uri) As Boolean

參數

baseUri
Uri

基底 URI。The base URI.

relativeUri
Uri

要加入基底 Uri 的相對 URI。The relative URI to add to the base Uri.

result
Uri

當這個方法傳回時,會包含從 UribaseUri 建構的 relativeUriWhen this method returns, contains a Uri constructed from baseUri and relativeUri. 這個參數會以未初始化的狀態傳遞。This parameter is passed uninitialized.

傳回

Boolean

如果已成功建立 Uri 則為 true,否則為 falsetrue if the Uri was successfully created; otherwise, false.

例外狀況

baseUrinullbaseUri is null.

備註

如果此方法傳回 true ,則新的 Uri 會在中 resultIf this method returns true, the new Uri is in result.

這個方法會建立 URI、將它置於標準格式,然後進行驗證。This method constructs the URI, puts it in canonical form, and validates it. 如果發生未處理的例外狀況,此方法會將它攔截。If an unhandled exception occurs, this method catches it. 如果您想要建立 Uri ,並取得例外狀況,請使用其中一個 Uri 函數。If you want to create a Uri and get exceptions use one of the Uri constructors.

適用於