using (C# 參考)
using
關鍵字有兩個主要用途:
- 語句
using
會在處置對象的結尾定義範圍:
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);
}
- 指示
using
詞 會建立命名空間的別名,或匯入在其他命名空間中定義的類型:
using System;
using System.IO;
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應