Search code examples
c#idatareader

Should IDataReader::Dispose call IDataReader::Close?


I'm implementing IDataReader and I wonder if the implementation of Dispose is supposed to call Close or not.

Also, should Close call Dispose?

My guess is that Close shouldn't call Dispose and Dispose can call Close since AFAIK you should be able to call Dispose as many times as you want in any object. But this is just a guess and I'd rather hear an expert's opinion.


Solution

  • Close() and Dispose() should do the same thing (one should call the other).
    However, Close() does not need to be callable multiple times.

    You should inherit the base DbDataReader class instead of re-implementing the whole thing yourself; if so, you'll need to override the abstract Close().