为什么在此代码中流保持打开状态?

use*_*153 2 c# stream

我从书中的一段代码中得到一个问题:C#编程考试70-483这是代码:

WebRequest request = WebRequest.Create(“http://www.microsoft.com”);
WebResponse response = request.GetResponse();
StreamReader responseStream = new StreamReader(response.GetResponseStream());
string responseText = responseStream.ReadToEnd();
Console.WriteLine(responseText); // Displays the HTML of the website
response.Close();
Run Code Online (Sandbox Code Playgroud)

我的问题是为什么在这个例子中没有关闭responseStream?为什么只关闭响应对象?

nsg*_*cev 5

调用WebResponse.Close implicity会关闭响应流.

取自这里 - http://msdn.microsoft.com/en-us/library/system.net.webresponse.close(v=vs.110).aspx

Close方法清除WebResponse使用的资源,并通过调用Stream.Close方法关闭基础流.