Why calling Dispose() on BinaryReader results in compile error?

前端 未结 3 1445
时光取名叫无心
时光取名叫无心 2021-01-15 03:41

I have the following class which uses BinaryReader internally and implements IDisposable.

class DisposableClass : IDisposable
    {
        private BinaryReader r         


        
3条回答
  •  广开言路
    2021-01-15 04:25

    Actually they have chosen to use Close() instead of Dispose() Dispose has been explicitly implemented. Which is why you can't see it.

    However Close does the same thing as dispose and this is the method they want you to use. Reflector gives the following disassembly for the Close method

    public virtual void Close()
    {
        this.Dispose(true);
    }
    

    Close() is used because it is a better choice of words in the context of a binary reader.

提交回复
热议问题