PhysicalAddress.Parse 方法

定义

重载

Parse(ReadOnlySpan<Char>)

分析指定的范围,并将其内容存储为由此方法返回的 PhysicalAddress 的地址字节。Parses the specified span and stores its contents as the address bytes of the PhysicalAddress returned by this method.

Parse(String)

分析指定的 String 并将其内容存储为由此方法返回的 PhysicalAddress 的地址字节。Parses the specified String and stores its contents as the address bytes of the PhysicalAddress returned by this method.

Parse(ReadOnlySpan<Char>)

分析指定的范围,并将其内容存储为由此方法返回的 PhysicalAddress 的地址字节。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

参数

address
ReadOnlySpan<Char>

一个范围,包含用于初始化由此方法返回的 PhysicalAddress 实例的地址。A span containing the address that will be used to initialize the PhysicalAddress instance returned by this method.

返回

PhysicalAddress

具有指定地址的 PhysicalAddress 实例。A PhysicalAddress instance with the specified address.

例外

address 包含非法硬件地址或包含格式不正确的字符串。address contains an illegal hardware address or contains a string in the incorrect format.

示例

下面的代码示例 PhysicalAddress 通过调用方法来创建一个 Parse 实例。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;
}

注解

address参数必须包含一个字符串,该字符串只能包含数字和小写字母作为十六进制数字。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

请注意,包含的地址 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.

使用 GetAddressBytes 方法从现有实例中检索地址 PhysicalAddressUse the GetAddressBytes method to retrieve the address from an existing PhysicalAddress instance.

适用于

Parse(String)

分析指定的 String 并将其内容存储为由此方法返回的 PhysicalAddress 的地址字节。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

参数

address
String

一个 String,包含用于初始化由此方法返回的 PhysicalAddress 实例的地址。A String containing the address that will be used to initialize the PhysicalAddress instance returned by this method.

返回

PhysicalAddress

具有指定地址的 PhysicalAddress 实例。A PhysicalAddress instance with the specified address.

例外

address 包含非法硬件地址或包含格式不正确的字符串。address contains an illegal hardware address or contains a string in the incorrect format.

示例

下面的代码示例 PhysicalAddress 通过调用方法来创建一个 Parse 实例。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;
}

注解

address参数必须包含一个字符串,该字符串只能包含数字和小写字母作为十六进制数字。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

请注意,包含的地址 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.

使用 GetAddressBytes 方法从现有实例中检索地址 PhysicalAddressUse the GetAddressBytes method to retrieve the address from an existing PhysicalAddress instance.

适用于