Vai al contenuto


Foto

[@Tigercoso] l'using in c#


Questa discussione e' stata archiviata Questo significa che non e' possibile rispondere
4 risposte a questa discussione

#1 toyo

toyo

    sono triste

  • Donatori di sperma
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 44.037 Messaggi:

Inviato 25 settembre 2011 - 12:19

serve per fare la delete subito alla fine del blocco di codice, senza aspettare il ragno?

FIRMA FOTTUTAMENTE EDITATA. IL FOTTUTO STAFF.
 

Mai piĆ¹ giorni felici


#2 toyo

toyo

    sono triste

  • Donatori di sperma
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 44.037 Messaggi:

Inviato 25 settembre 2011 - 14:35

Si

#3 TigerShark

TigerShark

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 16.685 Messaggi:

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 gugoXX

gugoXX

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStelletta
  • 5.440 Messaggi:

Inviato 25 settembre 2011 - 14:57

Ci sono altri 2 usi della keyword "using"
Se non siete precisi, siatelo. :megusta:
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.

#5 toyo

toyo

    sono triste

  • Donatori di sperma
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 44.037 Messaggi:

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.