Edit

Share via


IPAddress Constructors

Definition

Initializes a new instance of the IPAddress class.

Overloads

IPAddress(Byte[])

Initializes a new instance of the IPAddress class with the address specified as a Byte array.

IPAddress(Int64)

Initializes a new instance of the IPAddress class with the address specified as an Int64.

IPAddress(ReadOnlySpan<Byte>)

Initializes a new instance of the IPAddress class with the address specified as a byte span.

IPAddress(Byte[], Int64)

Initializes a new instance of the IPAddress class with the address specified as a Byte array and the specified scope identifier.

IPAddress(ReadOnlySpan<Byte>, Int64)

Initializes a new instance of the IPAddress class with the address specified as a byte span and the specified scope identifier.

IPAddress(Byte[])

Source:
IPAddress.cs
Source:
IPAddress.cs
Source:
IPAddress.cs

Initializes a new instance of the IPAddress class with the address specified as a Byte array.

C#
public IPAddress(byte[] address);

Parameters

address
Byte[]

The byte array value of the IP address.

Exceptions

address is null.

address contains a bad IP address.

Remarks

The IPAddress is created with the Address property set to address.

If the length of address is 4, IPAddress(Byte[]) constructs an IPv4 address; otherwise, an IPv6 address with a scope of 0 is constructed.

The Byte array is assumed to be in network byte order with the most significant byte first in index position 0.

Applies to

.NET 10 and other versions
Product Versions
.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, 10
.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.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

IPAddress(Int64)

Source:
IPAddress.cs
Source:
IPAddress.cs
Source:
IPAddress.cs

Initializes a new instance of the IPAddress class with the address specified as an Int64.

C#
public IPAddress(long newAddress);

Parameters

newAddress
Int64

The long value of the IP address. For example, the value 0x2414188f in big-endian format would be the IP address "143.24.20.36".

Exceptions

newAddress < 0 or

newAddress > 0x00000000FFFFFFFF

Remarks

The IPAddress instance is created with the Address property set to newAddress.

The Int64 value is assumed to be in network byte order.

Applies to

.NET 10 and other versions
Product Versions
.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, 10
.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.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

IPAddress(ReadOnlySpan<Byte>)

Source:
IPAddress.cs
Source:
IPAddress.cs
Source:
IPAddress.cs

Initializes a new instance of the IPAddress class with the address specified as a byte span.

C#
public IPAddress(ReadOnlySpan<byte> address);

Parameters

address
ReadOnlySpan<Byte>

The byte representation of the IP address, in network byte order, with the most significant byte first in index position 0.

Exceptions

address contains a bad IP address.

Remarks

The IPAddress is created with the Address property set to address.

If the length of address is 4, this method constructs an IPv4 address; otherwise, an IPv6 address with a scope of 0 is constructed.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

IPAddress(Byte[], Int64)

Source:
IPAddress.cs
Source:
IPAddress.cs
Source:
IPAddress.cs

Initializes a new instance of the IPAddress class with the address specified as a Byte array and the specified scope identifier.

C#
public IPAddress(byte[] address, long scopeid);

Parameters

address
Byte[]

The byte array value of the IP address.

scopeid
Int64

The long value of the scope identifier.

Exceptions

address is null.

address contains a bad IP address.

scopeid < 0 or

scopeid > 0x00000000FFFFFFFF

Remarks

This constructor instantiates an IPv6 address. The scopeid identifies a network interface in the case of a link-local address. The scope is valid only for link-local and site-local addresses.

The Byte array is assumed to be in network byte order with the most significant byte first in index position 0.

Applies to

.NET 10 and other versions
Product Versions
.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, 10
.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.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

IPAddress(ReadOnlySpan<Byte>, Int64)

Source:
IPAddress.cs
Source:
IPAddress.cs
Source:
IPAddress.cs

Initializes a new instance of the IPAddress class with the address specified as a byte span and the specified scope identifier.

C#
public IPAddress(ReadOnlySpan<byte> address, long scopeid);

Parameters

address
ReadOnlySpan<Byte>

The byte span value of the IP address.

scopeid
Int64

The long value of the scope identifier.

Exceptions

address contains a bad IP address.

scopeid < 0

-or-

scopeid > 0x00000000FFFFFFFF

Remarks

This constructor instantiates an IPv6 address. The scopeid identifies a network interface in the case of a link-local address. The scope is valid only for link-local and site-local addresses.

The byte span is assumed to be in network byte order with the most significant byte first in index position 0.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1