다음을 통해 공유


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 개체입니다.

array<PhysicalAddress^>^ StoreNetworkInterfaceAddresses()
{
   IPGlobalProperties^ computerProperties = IPGlobalProperties::GetIPGlobalProperties();
   array<NetworkInterface^>^nics = NetworkInterface::GetAllNetworkInterfaces();
   if ( nics == nullptr || nics->Length < 1 )
   {
      Console::WriteLine( L"  No network interfaces found." );
      return nullptr;
   }

   array<PhysicalAddress^>^ addresses = gcnew array<PhysicalAddress^>(nics->Length);
   int i = 0;
   IEnumerator^ myEnum2 = nics->GetEnumerator();
   while ( myEnum2->MoveNext() )
   {
      NetworkInterface^ adapter = safe_cast<NetworkInterface^>(myEnum2->Current);
      IPInterfaceProperties^ properties = adapter->GetIPProperties();
      PhysicalAddress^ address = adapter->GetPhysicalAddress();
      array<Byte>^bytes = address->GetAddressBytes();
      PhysicalAddress^ newAddress = gcnew PhysicalAddress( bytes );
      addresses[ i++ ] = newAddress;
   }

   return addresses;
}
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새 instance 만들 수도 있습니다.

적용 대상