gpt4 book ai didi

c# - 在带有 continue 的循环中使用

转载 作者:行者123 更新时间:2023-12-04 23:23:08 24 4
gpt4 key购买 nike

给出以下示例代码:

var count = 0;
while (count < 5)
{
using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri))
using (var response = await StaticHttpClient.Client.SendAsync(request))
{
if (!response.IsSuccessStatusCode)
{
switch ((int)response.StatusCode)
{
case 500:
case 504:
continue;
}
}
else
{ ... }
}

count++;
}

那些 IDisposable 对象会在此方法中泄漏内存还是会正确调用 Dispose 方法? (开关中缺少许多情况,我不关心那里的效率)。

最佳答案

Will those IDisposable objects leak memory in this method or will the Dispose method be properly called?



一次性用品将获得 Dispose()因为您使用了 using,所以正确调用了它们陈述。当您 continue , Dispose()方法将在循环的下一次迭代之前被调用。

关于c# - 在带有 continue 的循环中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18970092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com