serve per fare la delete subito alla fine del blocco di codice, senza aspettare il ragno?
[@Tigercoso] l'using in c#
Iniziato da
toyo
, 25 set 2011 12:19
4 risposte a questa discussione
#1
Inviato 25 settembre 2011 - 12:19
FIRMA FOTTUTAMENTE EDITATA. IL FOTTUTO STAFF.
Mai piĆ¹ giorni felici
#2
Inviato 25 settembre 2011 - 14:35
Si
#3
Inviato 25 settembre 2011 - 14:47
e' un syntactic sugar che serve a garantire che l'esecuzione della Dispose di un'oggetto venga sempre effettuata alla fine del blocco, anche in caso di eccezioni.
using (var con = ConnectionPool.GetConnection()) { DoSomethingWith(connection); }equivale a:
var con = ConnectionPool.GetConnection(); try { DoSomethingWith(connection); } finally { if (con != null) ((IDisposable)con).Dispose(); }
I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past I will turn the inner eye to see its path. Where the fear has gone there will be nothing. Only I will remain.
#4
Inviato 25 settembre 2011 - 14:57
Ci sono altri 2 usi della keyword "using"
Se non siete precisi, siatelo.
Se non siete precisi, siatelo.
L'unico effetto positivo del comunismo e' quello di far produrre doppio a Civilization
The above post is my PERSONAL OPINION and DOES NOT REPRESENT the official position of any company or entity, and does not derive either from official or internal data of any company I am dealing with.
The above post is my PERSONAL OPINION and DOES NOT REPRESENT the official position of any company or entity, and does not derive either from official or internal data of any company I am dealing with.
#5
Inviato 25 settembre 2011 - 15:03
e' un syntactic sugar che serve a garantire che l'esecuzione della Dispose di un'oggetto venga sempre effettuata alla fine del blocco, anche in caso di eccezioni.
using (var con = ConnectionPool.GetConnection()) { DoSomethingWith(connection); }equivale a:var con = ConnectionPool.GetConnection(); try { DoSomethingWith(connection); } finally { if (con != null) ((IDisposable)con).Dispose(); }
Come pensavo, grazie.