嗨,
閱讀一些網頁後,我還是不明白,在C#中的Dispose和Close方法之間的區別。
讓我們的樣本:
using (SqlConnection sqlConnection = new SqlConnection())
{
// Execute an insert statement (no breaks, exceptions, returns, etc.)
}
,第二個:
SqlConnection sqlConnection = new SqlConnection();
// Execute an insert statement (no breaks, exceptions, returns, etc.)
sqlConnection.Close();
那些是兩段代碼相似?都可用只是爲了方便(因爲在有些情況下using
不是一個解決辦法?或者有在活動的差異?
那麼,爲什麼一些類提供Close
方法和應,當我把一個Close
方法IDisposable
類我創建?
Duplicate http://stackoverflow.com/questions/61092/close-and-dispose-which-to-call – chilltemp 2010-07-09 22:11:41
感謝注意它是重複的。我在發佈前搜索,但沒有找到它。我正在結束這個問題。 – 2010-07-09 22:28:04