語言

PhysicalAddress(Byte[]) 建構函式

定義

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

public:
 PhysicalAddress(cli::array <System::Byte> ^ address);
public PhysicalAddress(byte[] address);
new System.Net.NetworkInformation.PhysicalAddress : byte[] -> System.Net.NetworkInformation.PhysicalAddress
Public Sub New (address As Byte())

參數

address
Byte[]

一個 Byte 包含位址的陣列。

範例

以下程式碼範例會建立一個新的 PhysicalAddress 物件。

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

適用於