Dibaca dalam bahasa Inggeris Edit

Kongsi melalui


UriBuilder Constructors

Definition

Initializes a new instance of the UriBuilder class.

Overloads

UriBuilder()

Initializes a new instance of the UriBuilder class.

UriBuilder(String)

Initializes a new instance of the UriBuilder class with the specified URI.

UriBuilder(Uri)

Initializes a new instance of the UriBuilder class with the specified Uri instance.

UriBuilder(String, String)

Initializes a new instance of the UriBuilder class with the specified scheme and host.

UriBuilder(String, String, Int32)

Initializes a new instance of the UriBuilder class with the specified scheme, host, and port.

UriBuilder(String, String, Int32, String)

Initializes a new instance of the UriBuilder class with the specified scheme, host, port number, and path.

UriBuilder(String, String, Int32, String, String)

Initializes a new instance of the UriBuilder class with the specified scheme, host, port number, path, and query string or fragment identifier.

UriBuilder()

Source:
UriBuilder.cs
Source:
UriBuilder.cs
Source:
UriBuilder.cs

Initializes a new instance of the UriBuilder class.

public UriBuilder ();

Remarks

The parameterless constructor creates a new instance of the UriBuilder class with its properties initialized as follows.

Property Initial Value
Fragment Empty
Host "loopback"
Password Empty
Path "/"
Port -1
Query Empty
Scheme "http"
UserName Empty

Applies to

.NET 9 dan versi lain
Produk Versi
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

UriBuilder(String)

Source:
UriBuilder.cs
Source:
UriBuilder.cs
Source:
UriBuilder.cs

Initializes a new instance of the UriBuilder class with the specified URI.

public UriBuilder (string uri);

Parameters

uri
String

A URI string.

Exceptions

uri is null.

uri is a zero-length string or contains only spaces.

-or-

The parsing routine detected a scheme in an invalid form.

-or-

The parser detected more than two consecutive slashes in a URI that does not use the "file" scheme.

-or-

uri is not a valid URI.

Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.

Remarks

This constructor initializes a new instance of the UriBuilder class with the Fragment, Host, Path, Port, Query, Scheme, and Uri properties set as specified in uri.

If uri does not specify a scheme, the scheme defaults to "http:".

Applies to

.NET 9 dan versi lain
Produk Versi
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

UriBuilder(Uri)

Source:
UriBuilder.cs
Source:
UriBuilder.cs
Source:
UriBuilder.cs

Initializes a new instance of the UriBuilder class with the specified Uri instance.

public UriBuilder (Uri uri);

Parameters

uri
Uri

An instance of the Uri class.

Exceptions

uri is null.

Remarks

This constructor initializes a new instance of the UriBuilder class with the Fragment, Host, Path, Port, Query, Scheme, and Uri properties set as specified in uri.

Applies to

.NET 9 dan versi lain
Produk Versi
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

UriBuilder(String, String)

Source:
UriBuilder.cs
Source:
UriBuilder.cs
Source:
UriBuilder.cs

Initializes a new instance of the UriBuilder class with the specified scheme and host.

public UriBuilder (string schemeName, string hostName);
public UriBuilder (string? schemeName, string? hostName);

Parameters

schemeName
String

An Internet access protocol.

hostName
String

A DNS-style domain name or IP address.

Examples

The following example creates a UriBuilder instance that contains the URI http://www.contoso.com/.

UriBuilder myUri = new UriBuilder("http","www.contoso.com");

Remarks

The UriBuilder instance is initialized with the Scheme property set to schemeName and the Host property set to hostName. Port is initialized to the value -1 to indicate the default port for the scheme should be used, and the Path property is set to the slash character (/).

Applies to

.NET 9 dan versi lain
Produk Versi
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

UriBuilder(String, String, Int32)

Source:
UriBuilder.cs
Source:
UriBuilder.cs
Source:
UriBuilder.cs

Initializes a new instance of the UriBuilder class with the specified scheme, host, and port.

public UriBuilder (string scheme, string host, int portNumber);
public UriBuilder (string? scheme, string? host, int portNumber);

Parameters

scheme
String

An Internet access protocol.

host
String

A DNS-style domain name or IP address.

portNumber
Int32

An IP port number for the service.

Exceptions

portNumber is less than -1 or greater than 65,535.

Examples

The following example creates a UriBuilder instance that contains the URI http://www.contoso.com:8080/.

UriBuilder myUri = new UriBuilder("http","www.contoso.com",8080);

Remarks

The UriBuilder instance is initialized with the Scheme property set to schemeName, the Host property set to hostName, and the Port property set to portNumber. The Path property is set to the slash character (/).

If the portNumber is set to a value of -1, this indicates that the default port value for the scheme will be used to connect to the host.

Applies to

.NET 9 dan versi lain
Produk Versi
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

UriBuilder(String, String, Int32, String)

Source:
UriBuilder.cs
Source:
UriBuilder.cs
Source:
UriBuilder.cs

Initializes a new instance of the UriBuilder class with the specified scheme, host, port number, and path.

public UriBuilder (string scheme, string host, int port, string pathValue);
public UriBuilder (string? scheme, string? host, int port, string? pathValue);

Parameters

scheme
String

An Internet access protocol.

host
String

A DNS-style domain name or IP address.

port
Int32

An IP port number for the service.

pathValue
String

The path to the Internet resource.

Exceptions

port is less than -1 or greater than 65,535.

Examples

The following example creates a UriBuilder instance that contains the URI http://www.contoso.com:8080/index.htm.

UriBuilder myUri = new UriBuilder("http","www.contoso.com",8080,"index.htm");

Remarks

The UriBuilder instance is initialized with the Scheme property set to schemeName, the Host property set to hostName, the Port property set to portNumber, and the Path property set to pathValue.

If the portNumber is set to a value of -1, this indicates that the default port value for the scheme will be used to connect to the host.

Applies to

.NET 9 dan versi lain
Produk Versi
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

UriBuilder(String, String, Int32, String, String)

Source:
UriBuilder.cs
Source:
UriBuilder.cs
Source:
UriBuilder.cs

Initializes a new instance of the UriBuilder class with the specified scheme, host, port number, path, and query string or fragment identifier.

public UriBuilder (string scheme, string host, int port, string path, string extraValue);
public UriBuilder (string? scheme, string? host, int port, string? path, string? extraValue);

Parameters

scheme
String

An Internet access protocol.

host
String

A DNS-style domain name or IP address.

port
Int32

An IP port number for the service.

path
String

The path to the Internet resource.

extraValue
String

A query string or fragment identifier.

Exceptions

extraValue is neither null nor Empty, nor does a valid fragment identifier begin with a number sign (#), nor a valid query string begin with a question mark (?).

port is less than -1 or greater than 65,535.

Examples

The following example creates a UriBuilder instance that contains the URI http://www.contoso.com:8080/index.htm#top.

UriBuilder myUri = new UriBuilder("http","www.contoso.com",8080,"index.htm","#top");

Remarks

The UriBuilder instance is initialized with the Scheme property set to schemeName, the Host property set to hostName, the Port property set to portNumber, and the Path property set to pathValue. If extraValue begins with a number sign (#), then Fragment is set to extraValue. If extraValue begins with a question mark (?), then Query is set to extraValue.

If the portNumber is set to a value of -1, this indicates that the default port value for the scheme will be used to connect to the host.

Applies to

.NET 9 dan versi lain
Produk Versi
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0