你可以告诉我在执行以下代码时内存中发生了什么:
情况1:
public static void Execute()
{
foreach(var text in DownloadTexts())
{
Console.WriteLine(text);
}
}
public static IEnumerable<string> DownloadTexts()
{
foreach(var url in _urls)
{
using (var webClient = new WebClient())
{
yield return webClient.DownloadText(url);
}
}
}
Run Code Online (Sandbox Code Playgroud)
让我们假设在第一次迭代后我得到html1.
什么时候从内存中清除html1?
谢谢
**编辑**
案例2:
public static void Execute()
{
var values = DownloadTexts();
foreach(var text in values)
{
Console.WriteLine(text);
}
}
public static IEnumerable<string> DownloadTexts()
{
foreach(var url in _urls)
{
using (var webClient = new WebClient())
{ …Run Code Online (Sandbox Code Playgroud)