views:

218

answers:

2

Perhaps my eyes are fooling me, but how is it that in .NET 2.0, XmlReader implements Dispose but does not have a Dispose() method? I see it has Dispose(bool), but not a parameterless overload.

+1  A: 

It implements it explicitly System.IDisposable.Dispose(). Dispose(boolean) is a normal method that does this ...

protected virtual void Dispose(bool disposing)
{
    if (this.ReadState != ReadState.Closed)
    {
        this.Close();
    }
}
JP Alioto
Thanks. I knew it was something simple I had just glossed over.
A: 

... so you need to call it for ex. this way

    XmlReader r = XmlReader.Create(s);
    ((IDisposable)r).Dispose();
Ariel
A using block works too, because it implicitly casts to IDisposable.
...I suppose I shouldn't have used the word "implicit," given the context of the conversation.