问题描述
我正在阅读并注意到了这一点:
I'm reading the documentation on TcpClient.Close() and noticed this:
请纠正我,如果我错了,但这表示如果在 TcpClient
上调用 Close()
, c $ c> NetworkStream 也将被关闭。
So, correct me if I'm wrong but this says that if one calls Close()
on the TcpClient
that the NetworkStream
will also be closed.
那么为什么在代码示例的末尾都是
So then why at the end of the code example are both Close()
called?
networkStream.Close();
tcpClient.Close();
只调用 tcpClient.Close()会一样好吗?
?
推荐答案
回答此问题,因为没有人这样做,所以我可以接受答案。
Responding to this question since no one else did so that I may accept an answer.
根据Hans的说法,不需要调用NetworkStream.Close(),因为TcpClient.Close()会关闭其底层NetworkStream。
According to Hans, calling NetworkStream.Close() is unnecessary because TcpClient.Close() closes its underlying NetworkStream.
这篇关于是否需要同时关闭NetworkStream和TcpClient或仅关闭TcpClient?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!