I've searched for info, but I'm still confused. What is the best practice for Dispose() in this scenario and why?
(And what are the code tags? doesn't seem to work.
Code:
class LineReader : ILineReader // derived from IDispose
{
StreamReader _file;
bool _eof = false;
public LineReader(ref string fileName)
{
_file = new StreamReader(fileName);
}
// Interface implementation
public bool AtEof { get { return _eof; } }
public String ReadNextLine()
{
string line = null;
try
{
if (_file.Peek() >= 0)
{
line = _file.ReadLine();
}
else
{
_eof = true;
}
}
catch (Exception e)
{
Console.WriteLine("ReadNextLine() exception: " + e.Message);
}
return line;
}
// For IDisposable
public void Dispose()
{
// What is best practice?
}
}