看板 C_Sharp 關於我們 聯絡資訊
各位好 想請教一個問題 public sealed class ConnectionManager { public static SqlConnection GetWebConnection() { string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection connection = new SqlConnection(connectionString); connection.Open(); return connection; } } =============================================== 請問如果我這樣寫 using (SqlCommand command = new SqlCommand(sql, ConnectionManager.GetWebConnection())) { //my statment } 是不是不用再close connection? 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.175.124.66
virdust2003:對,但不是個好習慣 01/15 12:58
bbcust:請問不是好習慣的原因是? 01/16 14:20
bbcust:using不就是為了方便這樣使用而產生的嗎? 01/16 14:20
Abbee:我覺得只要new IDispose的元件就用using才是好習慣 01/16 18:34