using System.Drawing; class a { public static void Main() { using (Font MyFont = new Font("Arial", 10.0f), MyFont2 = new Font("Arial", 10.0f)) { // use MyFont and MyFont2 } // compiler will call Dispose on MyFont and MyFont2 Font MyFont3 = new Font("Arial", 10.0f); using (MyFont3) { // use MyFont3 } // compiler will call Dispose on MyFont3 } }
将fill的结果赋给一个datatable对象后,dataset也可以dispose
class a
{
public static void Main()
{
using (Font MyFont = new Font("Arial", 10.0f), MyFont2 = new Font("Arial", 10.0f))
{
// use MyFont and MyFont2
} // compiler will call Dispose on MyFont and MyFont2 Font MyFont3 = new Font("Arial", 10.0f);
using (MyFont3)
{
// use MyFont3
} // compiler will call Dispose on MyFont3 }
}
{
string myInsertQuery = "Drop Table [MyTable]";
SqlCommand myCommand = new SqlCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
}