Edit

Share via


PhysicalAddress.Parse Method

Definition

Overloads

Parse(ReadOnlySpan<Char>)

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

Parse(String)

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

Parse(ReadOnlySpan<Char>)

Source:
PhysicalAddress.cs
Source:
PhysicalAddress.cs
Source:
PhysicalAddress.cs

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

public static System.Net.NetworkInformation.PhysicalAddress Parse (ReadOnlySpan<char> address);

Parameters

address
ReadOnlySpan<Char>

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

Returns

A PhysicalAddress instance with the specified address.

Exceptions

address contains an illegal hardware address or contains a string in the incorrect format.

Examples

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

public static PhysicalAddress? StrictParseAddress(ReadOnlySpan<char> address)
{
    PhysicalAddress newAddress = PhysicalAddress.Parse(address);
    if (PhysicalAddress.None.Equals(newAddress))
        return null;

    return newAddress;
}

Remarks

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

001122334455

00-11-22-33-44-55

0011.2233.4455

00:11:22:33:44:55

F0-E1-D2-C3-B4-A5

f0-e1-d2-c3-b4-a5

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

Applies to

.NET 9 and other versions
Product Versions
.NET 5, 6, 7, 8, 9

Parse(String)

Source:
PhysicalAddress.cs
Source:
PhysicalAddress.cs
Source:
PhysicalAddress.cs

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

public static System.Net.NetworkInformation.PhysicalAddress Parse (string? address);
public static System.Net.NetworkInformation.PhysicalAddress Parse (string address);

Parameters

address
String

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

Returns

A PhysicalAddress instance with the specified address.

Exceptions

address contains an illegal hardware address or contains a string in the incorrect format.

Examples

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;
}

Remarks

The address parameter must contain a string that can only consist of numbers and letters as hexadecimal digits. In .NET Framework and .NET Core 3.1 and earlier, the letters must be uppercase. Some examples of string formats that are acceptable are as follows:

001122334455

00-11-22-33-44-55

0011.2233.4455 (.NET 5 and later versions only)

00:11:22:33:44:55 (.NET 5 and later versions only)

F0-E1-D2-C3-B4-A5

f0-e1-d2-c3-b4-a5 (.NET 5 and later versions only)

In .NET Framework and .NET Core 3.1 and earlier, 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.

Applies to

.NET 9 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
.NET Framework 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 2.0, 2.1