PhysicalAddress(Byte[]) Constructeur
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la classe 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())
L’exemple de code suivant crée un PhysicalAddress objet .
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;
}
Dans les scénarios courants, les applications n’ont pas besoin d’appeler ce constructeur ; les instances de cette classe sont retournées par la GetPhysicalAddress méthode .
Notez que vous pouvez également utiliser la Parse méthode pour créer un instance de PhysicalAddress.
Produit | Versions |
---|---|
.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 |
Commentaires sur .NET
.NET est un projet open source. Sélectionnez un lien pour fournir des commentaires: