C# 中 using 的三种使用方法
- 引入命名空间
using System; using System.Data;
- 使用别名
using sql = System.Data.SqlClient; namespace test { public class test2 { public test2() { sql.SqlConnection = new Sql.SqlConnection(); //.... } } }
- 利用 .NET 的 GC 机制,应用于实现了 IDisposable 接口的对象
using(SqlConnection cn = new SqlConnection("....")) { cn.Open(); using (SqlCommand cmd = new SqlCommand("...", cn)) { //.... } }
作者: 三角猫
http://www.zu14.cn/
转载请保留此信息