Environment.MachineName Proprietà

Definizione

Ottiene il nome NetBIOS del computer locale.

C#
public static string MachineName { get; }

Valore della proprietà

String

Il nome di questo computer.

Eccezioni

Non è possibile ottenere il nome del computer.

Esempio

Nell'esempio seguente viene visualizzato il nome del computer che esegue l'esempio di codice. Il nome del computer viene omesso dall'output di esempio per motivi di sicurezza.

C#
// Sample for the Environment.MachineName property
using System;

class Sample
{
    public static void Main()
    {
    Console.WriteLine();
//  <-- Keep this information secure! -->
    Console.WriteLine("MachineName: {0}", Environment.MachineName);
    }
}
/*
This example produces the following results:
(Any result that is lengthy, specific to the machine on which this sample was tested, or reveals information that should remain secure, has been omitted and marked "!---OMITTED---!".)

MachineName: !---OMITTED---!
*/

Commenti

Il nome di questo computer viene stabilito all'avvio del sistema quando il nome viene letto dal Registro di sistema. Se questo computer è un nodo in un cluster, viene restituito il nome del nodo.

Si applica a

Prodotto Versioni
.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
.NET Framework 1.1, 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
.NET Standard 1.5, 1.6, 2.0, 2.1