PhysicalAddress(Byte[]) Konstruktor
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginisialisasi instans baru kelas 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())
Parameter
Contoh
Contoh kode berikut membuat objek baru 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;
}
Keterangan
Dalam skenario umum, aplikasi tidak perlu memanggil konstruktor ini; instans kelas ini dikembalikan oleh GetPhysicalAddress metode .
Perhatikan bahwa Anda juga dapat menggunakan Parse metode untuk membuat instans PhysicalAddressbaru .
Berlaku untuk
Berkolaborasi dengan kami di GitHub
Sumber untuk konten ini dapat ditemukan di GitHub, yang juga dapat Anda gunakan untuk membuat dan meninjau masalah dan menarik permintaan. Untuk informasi selengkapnya, lihat panduan kontributor kami.