using (Referencia de C#)
La palabra clave using
tiene dos usos principales:
- La instrucción
using
define un ámbito al final del cual se elimina un objeto:
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 directiva
using
crea un alias para un espacio de nombres o importa tipos definidos en otros espacios de nombres:
using System;
using System.IO;
Consulte también
Col·laboreu amb nosaltres a GitHub
La font d'aquest contingut es pot trobar al GitHub, on també podeu crear i revisar problemes i sol·licituds d'extracció. Per obtenir més informació, consulteu la nostra guia per a col·laboradors.