Partilhar via


usando (referência C#)

A using palavra-chave tem dois usos principais:

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);
}
  • A using diretiva cria um alias para um namespace ou importa tipos definidos em outros namespaces:
using System;
using System.IO;

Consulte também