Export (0) Print
Expand All

PhysicalAddress.Parse Method

Parses the specified String and stores its contents as the address bytes of the PhysicalAddress returned by this method.

Namespace:  System.Net.NetworkInformation
Assembly:  System (in System.dll)

public static PhysicalAddress Parse(
	string address
)

Parameters

address
Type: System.String

A String containing the address that will be used to initialize the PhysicalAddress instance returned by this method.

Return Value

Type: System.Net.NetworkInformation.PhysicalAddress
A PhysicalAddress instance with the specified address.

ExceptionCondition
FormatException

The address parameter contains an illegal hardware address.

This exception also occurs if the address parameter contains a string in the incorrect format.

The address parameter must contain a string that can only consist of numbers and upper-case letters as hexadecimal digits. Some examples of string formats that are acceptable are as follows:

001122334455

00-11-22-33-44-55

F0-E1-D2-C3-B4-A5

Note that an address that contains f0-e1-d2-c3-b4-a5 will fail to parse and throw an exception.

Use the GetAddressBytes method to retrieve the address from an existing PhysicalAddress instance.

The following code example creates a PhysicalAddress instance by calling the Parse method.

public static PhysicalAddress StrictParseAddress(string address)
{
    PhysicalAddress newAddress = PhysicalAddress.Parse(address);
    if (PhysicalAddress.None.Equals(newAddress))
        return null;

    return newAddress;
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft