可能重複: What is the C# Using block and why should I use it? 我將一箇舊網站到C#,我不知道什麼時候,我應該使用 '使用'。有沒有一般的指導方針?我知道的好處,但我不是100%確定如何使用它。每次我'新'的方法/財產嗎? SqlConnection awesomeConn = new SqlConnection(connection);
我有一些代碼有很多重複。問題來自我正在處理嵌套IDisposable類型的事實。今天,我有東西,看起來像: public void UpdateFromXml(Guid innerId, XDocument someXml)
{
using (var a = SomeFactory.GetA(_uri))
using (var b = a.GetB(_id))
us