Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Valid way to use using
Message
 
À
21/11/2008 10:28:18
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Application:
Desktop
Divers
Thread ID:
01363486
Message ID:
01363508
Vues:
12
>Hi All,
>
>Just checking, is this a valid way to use the using statement in this case? Is the StreamWriter closed and disposed?

Yes. A "using" statement ends up being compiled as (essentially, not exactly):
try
{
   stream = File.Open(deleteListPath, FileMode.Open)
}
finally
{
   stream.Dispose();
}
I also just took a look at the Stream base class inside of Reflector and Close() basically does this:
this.Dispose(true);
GC.SuppressFinalize(this);
So a call to both Close and Dispose turns out to not be necessary. One or the other is fine.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform