小编WHo*_*ard的帖子

C# ForEach 循环三重结果

我使用 ForEach 循环从 3 个不同的 URL 返回状态代码以遍历结果。它返回的结果很好,但返回了 3 组结果。

public static List<Models.SiteStatus> GetStatus()
{
    statusList.Clear();

    // website urls to check
    string site1 = "https://www.google.com";
    string site2 = "https://www.google.com";
    string site3 = "https://www.google.com";

    int site1Status = 0;
    int site2Status = 0;
    int site3Status = 0;

    HttpStatusCode result = default;
    HttpWebResponse response = null;

    // add urls to a list to pass through
    List<Uri> urls = new List<Uri>();
    urls.Add(new Uri(site1));
    urls.Add(new Uri(site2));
    urls.Add(new Uri(site3));


    // check status per site
    foreach (Uri u …
Run Code Online (Sandbox Code Playgroud)

c# foreach

1
推荐指数
1
解决办法
150
查看次数

标签 统计

c# ×1

foreach ×1