Quantcast
Channel: using{} kullanımı
Viewing all articles
Browse latest Browse all 3

using{} kullanımı

$
0
0

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?





Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images