Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Valid way to use using
Message
 
To
21/11/2008 10:28:18
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Application:
Desktop
Miscellaneous
Thread ID:
01363486
Message ID:
01363508
Views:
10
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform