Condividi tramite


using (Riferimenti per C#)

La parola chiave using ha due usi principali:

  • L'istruzione using definisce un ambito alla fine del quale un oggetto viene eliminato:
string filePath = "example.txt";
string textToWrite = "Hello, this is a test message!";

// Use the using statement to ensure the StreamWriter is properly disposed of
using (StreamWriter writer = new StreamWriter(filePath))
{
    writer.WriteLine(textToWrite);
}
  • La using direttiva crea un alias per uno spazio dei nomi o importa tipi definiti in altri spazi dei nomi:
using System;
using System.IO;

Vedi anche