T
Tony Johansson
Hello!
Below is a snipped from a using clause.
Here I have a TextReader variable that is references a StreamReader object.
Just before this using block is finished the dispose method will be called
because the IDisposable interface is implemented.
I wonder in what class will dispose be called is it the dispose method in
class TextReader or the dispose in class StreamReader. Tell me also why is
it TextReader or StreamReader.
If I look in the documentation for dispose for class StreamReader it says
"Releases all resources used by the TextReader" object. I would say that the
dispose for class StreamReader would release all resources used by
StreamReader instead of TextReader.
I looked at documentation for the dispose method in TextReader and it was
not declared to be virtual so polymorfism will not be used.
using (TextReader reader = new StreamReader(fullPathname))
{
string line;
while ((line = reader.ReadLine()) != null)
{
source.Text += line + "\n";
}
}
//Tony
Below is a snipped from a using clause.
Here I have a TextReader variable that is references a StreamReader object.
Just before this using block is finished the dispose method will be called
because the IDisposable interface is implemented.
I wonder in what class will dispose be called is it the dispose method in
class TextReader or the dispose in class StreamReader. Tell me also why is
it TextReader or StreamReader.
If I look in the documentation for dispose for class StreamReader it says
"Releases all resources used by the TextReader" object. I would say that the
dispose for class StreamReader would release all resources used by
StreamReader instead of TextReader.
I looked at documentation for the dispose method in TextReader and it was
not declared to be virtual so polymorfism will not be used.
using (TextReader reader = new StreamReader(fullPathname))
{
string line;
while ((line = reader.ReadLine()) != null)
{
source.Text += line + "\n";
}
}
//Tony