M
Mike Labosh
Dim message As String = File.OpenText("FileNotification.html").ReadToEnd()
Because the StreamReader never got closed?
Because the StreamReader never got closed?
Dim message As String =
File.OpenText("FileNotification.html").ReadToEnd()
Because the StreamReader never got closed?
Yes. Better use "using"
(and if the file does not exist, you also have some trouble...)
string s;
using(StreamReader sr = File.OpenText("fn.txt))
{
s = sr.ReadToEnd();
}
I'm pretty familiar with C#, but what's this using() {} thing do?
Ok, am I nuts here? This seems silly to me. It requires 3 lines of
code:
using(//stuff)
{
//my stuff
}
To just do this?!?
Stuff.Dispose();
nntp://news.microsoft.com/microsoft.public.dotnet.framework/ said:
Mike Labosh said:Ok, am I nuts here? This seems silly to me. It requires 3 lines of code:
using(//stuff)
{
//my stuff
}
To just do this?!?
Stuff.Dispose();
using (Stuff stuff = new Stuff())
{
//my stuff
}
is equivalent to
Stuff stuff = new Stuff();
try
{
//my stuff
}
finally
{
stuff.Dispose();
}
is equivalent to
Stuff stuff = new Stuff();
try
{
//my stuff
}
finally
{
stuff.Dispose();
}
Jochen Kalmbach said:Hi David Browne,
Nope...
Mostly Dispose is a hidden member, and therfor cannot be called directly!
please)> said:Hum, it was my understanding that when Dispose() is not public, it's because
it should not be called directly and that some other method, usually
Close(); should be called instead of making an «
((IDisposable)d).Dispose(); ».