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);
static member TryCreate : string * UriKind * Uri -> bool

参数

uriString
String

表示 StringUriThe String representing the Uri.

uriKind
UriKind

URI 的类型。The type of the Uri.

result
Uri

此方法返回时,包含构造的 UriWhen this method returns, contains the constructed Uri.

返回

一个 Boolean 值。如果成功创建了 true,则该值为 Uri;否则为 falseA Boolean value that is true if the Uri was successfully created; otherwise, false.

注解

如果此方法返回 true,则新 Uriresult中。If 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);
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

基本 UriThe base Uri.

relativeUri
String

要添加到基 Uri 的相对 String(表示为 Uri)。The relative Uri, represented as a String, 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 值。如果成功创建了 true,则该值为 Uri;否则为 falseA Boolean value that is true if the Uri was successfully created; otherwise, false.

注解

如果此方法返回 true,则新 Uriresult中。If 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);
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

基本 UriThe base Uri.

relativeUri
Uri

要添加到基 Uri 的相对 UriThe 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 值。如果成功创建了 true,则该值为 Uri;否则为 falseA Boolean value that is true if the Uri was successfully created; otherwise, false.

异常

baseUrinullbaseUri is null.

注解

如果此方法返回 true,则新 Uriresult中。If 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.

适用于