正如标题所说:
TcpClient如何实现IDisposable而没有公共的Dispose方法呢?
发布于 2010-02-24 19:27:34
通过使用explicit interface implementation。而不是
public void Dispose()
{
    ...
}如果真是这样
void IDisposable.Dispose()
{
    ...
}各种其他类型都会这样做;有时是出于必要(例如,支持IEnumerable.GetEnumerator和IEnumerable<T>.GetEnumerator),而有时是为了在已知具体类型的情况下公开更合适的接口。
发布于 2010-02-24 19:30:48
参见explicit interface implementation。您需要显式地将TcpClient实例强制转换为IDisposable,或者将其包装在using() {...}块中。请注意,显式实现IDisposable的类通常提供公共Close()方法
https://stackoverflow.com/questions/2325546
复制相似问题