close
在 .Net 的環境下 資源的回收 是比較簡單的,但相對的簡單 也是需要付出一定的代價( 記憶體)
如何讓程式寫得更簡捷 有力是每個程式設計師 最基本的工作
在 .Net 回收 記憶體中的垃圾 除了交由系統本身外
還有之前介紹過的 GC
今天介紹 更為主動的 Using (Dispose 也是主動的一種 使用時機就看個人使用習慣)
VB.Net
Using some as new Object
End Using
C#
Using Object obj = new Object()
{
}
用 VB.Net 及 StreamWriter 做範例
Using sw As TextWriter = New StreamWriter("C:\test.txt")
Dim s As String = ""
s += "GlassID:," + lblGlassID.Text + "," + vbCrLf
s += "Measure Type:,Thickness,Auto," + vbCrLf
s += "Recipe Name:," + labSERecipeName.Text + "," + vbCrLf
sw.Write( sw.Write(s + vbCrLf))
End Using
如此 就可以在 使用完 SW 此物件後 自動銷毀
全站熱搜