Class IPAddress
Initializes a new instance of the IPAddress class.
Inherited Members
Namespace: System.Net
Assembly: System.Net.dll
Syntax
[Serializable]
public class IPAddress
Constructors
| Improve this Doc View SourceIPAddress(Byte[])
Initializes a new instance of the IPAddress class with the address specified as a Byte array.
Declaration
public IPAddress(byte[] address)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | 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.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
IPAddress(Int64)
Initializes a new instance of the IPAddress class with the address specified as an Int64.
Declaration
public IPAddress(long newAddress)
Parameters
Type | Name | Description |
---|---|---|
Int64 | newAddress | 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". |
Remarks
The IPAddress instance is created with the Address property set to newAddress
.
The Int64 value is assumed to be in network byte order.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
Fields
| Improve this Doc View SourceAny
Provides an IP address that indicates that the server must listen for client activity on all network interfaces. This field is read-only.
Declaration
public static readonly IPAddress Any
Field Value
Type | Description |
---|---|
IPAddress |
Loopback
Provides the IP loopback address. This field is read-only.
Declaration
public static readonly IPAddress Loopback
Field Value
Type | Description |
---|---|
IPAddress |
Properties
| Improve this Doc View SourceAddressFamily
Gets the address family of the IP address.
Declaration
public AddressFamily AddressFamily { get; }
Property Value
Type | Description |
---|---|
AddressFamily | Returns InterNetwork for IPv4 or InterNetworkV6 for IPv6. |
Methods
| Improve this Doc View SourceEquals(Object)
Compares two IP addresses.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | An IPAddress instance to compare to the current instance. |
Returns
Type | Description |
---|---|
Boolean |
Overrides
| Improve this Doc View SourceGetAddressBytes()
Provides a copy of the IPAddress as an array of bytes.
Declaration
public byte[] GetAddressBytes()
Returns
Type | Description |
---|---|
Byte[] | A Byte array. |
GetDefaultLocalAddress()
Retrieves an IP address that is the local default address.
Declaration
public static IPAddress GetDefaultLocalAddress()
Returns
Type | Description |
---|---|
IPAddress | The default IP address. |
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hash code for the current object. |
Overrides
| Improve this Doc View SourceParse(String)
Converts an IP address string to an IPAddress instance.
Declaration
public static IPAddress Parse(string ipString)
Parameters
Type | Name | Description |
---|---|---|
String | ipString | A string that contains an IP address in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6. |
Returns
Type | Description |
---|---|
IPAddress | An IPAddress instance. |
ToString()
Converts an Internet address to its standard notation.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | A string that contains the IP address in either IPv4 dotted-quad or in IPv6 colon-hexadecimal notation. |
Overrides
Remarks
The ToString() method converts the IP address that is stored in the Address property to either IPv4 dotted-quad or IPv6 colon-hexadecimal notation.