private int metod() { try { using (var connection = new SqlConnection(connectionString)) {
connection.Open(); using (var command = new SqlCommand("select MAX(Id) from Tablo", connection)) { SqlDataReader dataReader = command.ExecuteReader(); if (dataReader.Read()) return Convert.ToInt32(dataReader[0]); } } } catch (Exception) { MessageBox.Show("Veritabanı hatası"); }
return 0; }
Böyle bir kod bloğunda using içinde return kullanırsam connection ve command nesneleri yinede dispose edilir mi?