Does one need to close both NetworkStream and TcpClient, or just TcpClient?

后端 未结 4 1793
暖寄归人
暖寄归人 2021-02-13 00:13

I\'m reading the documentation on TcpClient.Close() and noticed this:

Calling this method will eventually result in the close of the associated Socket and

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-13 01:06

    NetworkStream and TcpClient implement IDisposable. So best practise in my opinion is to pack it into a using block, so you never need to close or dispose it manually.

提交回复
热议问题