Редагувати

Поділитися через


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);
public static System.Net.NetworkInformation.PhysicalAddress Parse (ReadOnlySpan<char> address);
static member Parse : ReadOnlySpan<char> -> System.Net.NetworkInformation.PhysicalAddress
Public Shared Function Parse (address As ReadOnlySpan(Of Char)) As PhysicalAddress

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

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(System::String ^ address);
public static System.Net.NetworkInformation.PhysicalAddress Parse (string? address);
public static System.Net.NetworkInformation.PhysicalAddress Parse (string address);
static member Parse : string -> System.Net.NetworkInformation.PhysicalAddress
Public Shared Function Parse (address As String) As PhysicalAddress

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.

PhysicalAddress^ StrictParseAddress( String^ address )
{
   PhysicalAddress^ newAddress = PhysicalAddress::Parse( address );
   if ( PhysicalAddress::None->Equals( newAddress ) )
      return nullptr;

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