using 关键字有三个主要用途:
1.using 语句定义一个范围,在此范围的末尾将释放对象:
cs
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);
}
2.using导入在其他命名空间中定义的类型:
cs
using System;
using System.IO;
3.using 在命名空间下,为命名空间或类型或结构体创建别名
cs
using Level = System.String;
using MyQuery = System.Linq;
~~~~~~