PhysicalAddress(Byte[]) 建構函式

定義

初始化 PhysicalAddress 類別的新執行個體。

C#
public PhysicalAddress(byte[] address);

參數

address
Byte[]

Byte 陣列,包含位址。

範例

下列程式代碼範例會建立新的 PhysicalAddress 物件。

C#
public static PhysicalAddress[]? StoreNetworkInterfaceAddresses()
{
    IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
    NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
    if (nics == null || nics.Length < 1)
    {
        Console.WriteLine("  No network interfaces found.");
        return null;
    }

    PhysicalAddress[] addresses = new PhysicalAddress[nics.Length];
    int i = 0;
    foreach (NetworkInterface adapter in nics)
    {
        IPInterfaceProperties properties = adapter.GetIPProperties();
        PhysicalAddress address = adapter.GetPhysicalAddress();
        byte[] bytes = address.GetAddressBytes();
        PhysicalAddress newAddress = new PhysicalAddress(bytes);
        addresses[i++] = newAddress;
    }
    return addresses;
}

備註

在常見的案例中,應用程式不需要呼叫此建構函式;方法會傳 GetPhysicalAddress 回這個類別的實例。

請注意,您也可以使用 Parse 方法來建立 的新實例 PhysicalAddress

適用於

產品 版本
.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, 10
.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