代码之家  ›  专栏  ›  技术社区  ›  CannibalSmith

TcpClient如何实现IDisposable而没有公共的Dispose方法?

  •  15
  • CannibalSmith  · 技术社区  · 16 年前

    2 回复  |  直到 16 年前
        1
  •  11
  •   Jon Skeet    16 年前

    通过使用 explicit interface implementation . 而不是

    public void Dispose()
    {
        ...
    }
    

    它会的

    void IDisposable.Dispose()
    {
        ...
    }
    

    其他类型的人也会这样做;有时是出于必要(例如支持 IEnumerable.GetEnumerator 和 IEnumerable<T>.GetEnumerator

        2
  •  3
  •   thecoop    16 年前

    看见 explicit interface implementation TcpClient 到 IDisposable ,或者把它包起来 using() {...} 可识别的 通常提供公共 Close() 方法